More regular expression help

Post Reply
barry.marcus
Posts: 288
Joined: Thu Nov 16, 2006 1:05 pm

More regular expression help

Post by barry.marcus »

Task 1: I'm looking to match, using rex, whenever the first "visible" character of a string is a plus sign. That is, the "+" could be the very first character, or it could be preceeded by any number of spaces, tabs, carriage returns, etc.

Task 2 is similar, but I want to match if the first visible character is NOT a plus sign. Again, in this case, I don't care about any characters such as spaces, tabs, CR, etc., at the beginning.

Thanks again for the help.
User avatar
jason112
Site Admin
Posts: 347
Joined: Tue Oct 26, 2004 5:35 pm

More regular expression help

Post by jason112 »

task 1: >>=\space*\+=
task 2: >>=\space*!\+=

Discussing the components:
>>= Two greater than symbols is the "anchor" sequence, and anchoring to an empty sequence (just the equals) at the beginning or end of the expression matches the beginning or end of the string. More built-in sequences, such as \alpha, \alnum, etc., are listed at http://www.thunderstone.com/site/vortex ... yntax.html

\space* The "\space" sequence is the C language character class, which includes space, tab, CR, LF, etc. The * means match 0 or more.

\+= Match exactly one plus. Plus is normally special (means "one or more of the previous set), so it must be escaped by a backslash when we want to match it literally.

!\+= Match exactly one character that ISN'T a plus
User avatar
mark
Site Admin
Posts: 5519
Joined: Tue Apr 25, 2000 6:56 pm

More regular expression help

Post by mark »

task 2 could also be >>=\space*[^+]=
barry.marcus
Posts: 288
Joined: Thu Nov 16, 2006 1:05 pm

More regular expression help

Post by barry.marcus »

Thank you very much! I appreciate the help.
Post Reply