Regualr Expression Puzzle

K

Ken

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
 
B

Ben

Ken said:
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 "[-+_/&]" .
 
O

Oliver Wong

Ken said:
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
 
U

ultimadj

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. :)

:D avid
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top