Velocity Reviews > Java > Regualr Expression Puzzle

# Regualr Expression Puzzle

Ken
Guest
Posts: n/a

 02-21-2007
Here's my pattern: "\\b[A-Z]([A-Z0-9]|([+-_/&](?=[A-Z0-9])))+\\b"

This pattern finds the string F1.3 . For the life of me I can't figure
out how the dot gets sucked in. Seems like it should find F1 . Can
someone explain?

Ken

Ben
Guest
Posts: n/a

 02-21-2007
Ken wrote:
> Here's my pattern: "\\b[A-Z]([A-Z0-9]|([+-_/&](?=[A-Z0-9])))+\\b"
>
> This pattern finds the string F1.3 . For the life of me I can't figure
> out how the dot gets sucked in. Seems like it should find F1 . Can
> someone explain?
>
> Ken
>

"[+-_/&]" is the set '+' to '_' plus '/' plus '&'. I'm not sure what you
are doing but you probably mean "[-+_/&]" .

Oliver Wong
Guest
Posts: n/a

 02-21-2007

"Ken" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> Here's my pattern: "\\b[A-Z]([A-Z0-9]|([+-_/&](?=[A-Z0-9])))+\\b"
>
> This pattern finds the string F1.3 . For the life of me I can't figure
> out how the dot gets sucked in. Seems like it should find F1 . Can
> someone explain?

Did you mean:

"\\b[A-Z]([A-Z0-9]|([+\\-_/&](?=[A-Z0-9])))+\\b"

?

- Oliver

ultimadj
Guest
Posts: n/a

 02-21-2007
On Feb 21, 11:18 am, "Ken" <(E-Mail Removed)> wrote:
> Here's my pattern: "\\b[A-Z]([A-Z0-9]|([+-_/&](?=[A-Z0-9])))+\\b"
>
> This pattern finds the string F1.3 . For the life of me I can't figure
> out how the dot gets sucked in. Seems like it should find F1 . Can
> someone explain?
>
> Ken

Hey Ken,
The period character is 0x46. In your expression, you stated '[+-_'
which means "match any character between '+' (0x43) and '_' (0x95)".
Since '.' (0x46) is within this range, it gets matched. '-' and '+'
should be escaped, though switching the order like Oliver did
obviously works as well.

Here's a great resource for understanding how the regex engines work:
http://www.regular-expressions.info

If this is helpful, please rate my post.

avid

 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 OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Adem C++ 42 11-04-2008 12:39 PM Adem C Programming 45 11-04-2008 12:39 PM Heinrich Piard Ruby 14 01-14-2008 06:46 AM sk A+ Certification 1 07-17-2004 05:19 PM VSK ASP .Net 2 08-24-2003 02:47 PM

Advertisments