Regualr Expression Puzzle

Discussion in 'Java' started by Ken, Feb 21, 2007.

  1. Ken

    Ken Guest

    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
    Ken, Feb 21, 2007
    #1
    1. Advertising

  2. Ken

    Ben Guest

    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 "[-+_/&]" .
    Ben, Feb 21, 2007
    #2
    1. Advertising

  3. Ken

    Oliver Wong Guest

    "Ken" <> wrote in message
    news:...
    > 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
    Oliver Wong, Feb 21, 2007
    #3
  4. Ken

    ultimadj Guest

    On Feb 21, 11:18 am, "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


    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
    ultimadj, Feb 21, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VSK
    Replies:
    2
    Views:
    2,267
  2. =?iso-8859-1?B?bW9vcJk=?=

    Matching abitrary expression in a regular expression

    =?iso-8859-1?B?bW9vcJk=?=, Dec 1, 2005, in forum: Java
    Replies:
    8
    Views:
    829
    Alan Moore
    Dec 2, 2005
  3. GIMME
    Replies:
    3
    Views:
    11,917
    vforvikash
    Dec 29, 2008
  4. snacktime
    Replies:
    13
    Views:
    552
    Dan Sommers
    Feb 22, 2005
  5. Heinrich Piard

    regualr expression (need help)

    Heinrich Piard, Jan 13, 2008, in forum: Ruby
    Replies:
    14
    Views:
    196
    Sebastian Hungerecker
    Jan 14, 2008
Loading...

Share This Page