Ask a Question related to PERL Miscellaneous, Design and Development.
-
bob #1
location of regular expression match
I apologize for another newbie question. How does one obtain the
starting character position of all regular expression matches in a
line or a paragraph?
Thank you.
bob Guest
-
Regular expression help
Hi, I'm pretty new to regular expressions. Before, I used to write long-winded and buggy segments of code with PHPs string functions to extract... -
Regular expression for both first and last name?
I'm new to regular expressions, can someone explain to me how I can write one that will check for 2 names, at least, for a name field? Thanks!... -
Regular expression bug?
All of CF's RE functions act in a weird way, contrary to the documentation (both CF's own, and the underlying Java Regex docs). The special... -
help on regular expression
Hi, I need some help on regular expression... i have following in variable $total_count $total_count = "##I USBP 000001 10:38:09(000)... -
[PHP] REGULAR EXPRESSION HELP
John wrote: Your "newline" may be \r\n or \r instead of just \n. -- ---John Holmes... Amazon Wishlist:... -
Amir Kadic #2
Re: location of regular expression match
bob wrote:
One way I can think of is using pos() in a loop:> I apologize for another newbie question. How does one obtain the
> starting character position of all regular expression matches in a
> line or a paragraph?
foreach $token (qw#foo bar#) {
$position= pos($line),"\n" if $line =~ /$token/g;
# now do something with it
}
I _hope_ there is a more elegant WTDI.
Amir
Amir Kadic Guest
-
Amir Kadic #3
Re: location of regular expression match
I wrote:
Please forget the q(,"\n")> $position= pos($line),"\n" if $line =~ /$token/g;
This was originally a print(), but then I thought,
'that man wants to _obtain_, not print the positions'...:)
Amir
Amir Kadic Guest
-
mooseshoes #4
Re: location of regular expression match
<snip>
> I apologize for another newbie question. How does one obtain the
> starting character position of all regular expression matches in a
> line or a paragraph?
> Thank you.
It is stored in the @- array (ie. $-[0] is the position at the start of a
match). Use //g modifier and \G anchor as needed. Check out perlretut and
perlre for more info.
Moose
mooseshoes Guest



Reply With Quote

