Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > scan a string from right to left using PRX expression

Reply
Thread Tools

scan a string from right to left using PRX expression

 
 
Philip Primak
Guest
Posts: n/a
 
      08-07-2005
Hi


I wonder if there is a way to scan a string from right to left using
PRX expression. For example I need to find the first space from the
right in string "I love you". So I want the pattern / / scan from right
to left and find as result space between "love" and "you" at position
7. I understand that it can be solved using pattern / [^ ]*$/ or using
strait pattern / / and trick like
position=length(string)-prxmat*ch(prx,reverse(string))+1 or something
like this. All those solutions do not force PRX functions to scan from
right to left but they just use tricks to get the last space found. I
am just curious if there is a option which would force PRX expressions
to make scan from right to left.


Thank you
Philip Primak
Genzyme Corp

 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      08-07-2005
"Philip Primak" <(E-Mail Removed)> wrote:
> Hi
>
> I wonder if there is a way to scan a string from right to left using
> PRX expression. For example I need to find the first space from the
> right in string "I love you".


I don't know what PRX is, but it seems like you could just reverse the
string before sending it to PRX.


> Thank you=20
> Philip Primak=20
> Genzyme Corp


Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
 
 
 
Peter Wyzl
Guest
Posts: n/a
 
      08-07-2005
<(E-Mail Removed)> wrote in message
news:20050807012011.654$(E-Mail Removed)...
: "Philip Primak" <(E-Mail Removed)> wrote:
: > Hi
: >
: > I wonder if there is a way to scan a string from right to left using
: > PRX expression. For example I need to find the first space from the
: > right in string "I love you".
:
: I don't know what PRX is, but it seems like you could just reverse the
: string before sending it to PRX.

<guess> Perl Regular eXpression </guess>

P


 
Reply With Quote
 
Veli-Pekka Tštilš
Guest
Posts: n/a
 
      08-07-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> "Philip Primak" <(E-Mail Removed)> wrote:
>> scan a string from right to left using PRX expression.
>> find the first space from the right in string "I love you".

> I don't know what PRX is,

Me neither.

> you could just reverse the string before sending it to PRX.

Or howabout using substr to extract part of a string and rindex to find the
last occurrence of a sub-string in a string.

Sample code:
use strict;
use warnings;
my $string = 'I love you';
print "The string is '$string'\n";

my $lastSpace = rindex $string, ' '; # string, substring, [offset]
print "The $[ based character index of last space is $lastSpace\n";

# find everything from last space onwards (including last space).
my $lastWord = substr $string, $lastSpace; # string, offset, [length]
print "text from $lastSpace to ", length($string) - 1, " is '$lastWord'\n";

Output:
The string is 'I love you'
The 0 based character index of last space is 6
text from 6 to 9 is ' you'

Hope this can be of help.

--
With kind regards Veli-Pekka Tštilš ((E-Mail Removed))
Accessibility, game music, synthesizers and programming:
http://www.student.oulu.fi/~vtatila/


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic Menu Items is not right aligned with Right to Left documen =?Utf-8?B?QmlzaG95?= ASP .Net 0 12-28-2006 11:39 AM
left(string, length) or right(string, length)? Sam ASP .Net 3 02-17-2005 12:01 PM
how to use .prx driver file Mrs Beeble Brock NZ Computing 6 02-05-2005 03:59 AM
Align javascript alert message to right AND / OR make the direction as RIGHT-TO-LEFT Oran Javascript 2 12-03-2004 04:34 PM
Tool to right click image in windows explorer and rotate image right or left 90 degrees siliconpi Digital Photography 2 11-29-2004 12:56 PM



Advertisments