#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2009
    Posts
    100
    Rep Power
    5

    Regex new lines and the . character


    the . character in a regular expression does not match new lines
    how do i match any character, including an unknown number of new lines?

    ive tried these:
    [.|\\s]*?
    (.|\\s)*?
    .|\\s*?
    none seem to work
  2. #2
  3. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,754
    Rep Power
    9397
    Normally a . will not match newline characters. You can change this in Java by passing Pattern's DOTALL constant as a flag to Pattern.compile().
    Without that, your second option
    Code:
    (.|\\s)*?
    should work (assuming you had to escape the backslash for a legitimate reason).

    As for the other two you tried,
    - [...] means a character set. Period (.) and pipe (|) lose their special meanings inside, so [.|\s] means "a period, a pipe, or whitespace".
    - .|\s* will match either a single character or many whitespace characters (because the * attaches to the \s, not to the whole expression).

    By the way we have a regex forum.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2009
    Posts
    100
    Rep Power
    5
    YESSSS IT WORKS!!!
    TYVM
    especially thank u for the explanation on the bracers, it was very clear

IMN logo majestic logo threadwatch logo seochat tools logo