Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 2 FirstFirst 12
Results 16 to 17 of 17

Thread: Regex help

  1. #16
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,274
    Thanks
    28
    Thanked 271 Times in 265 Posts
    Quote Originally Posted by narelle View Post
    Now I just need to consult the regex reference and work backwards to see what you've done
    A quick explanation:

    The delimiters are "Incident Title: " and a new line character sequence. That sequence of characters is carriage return and line feed (CRLF) in Windows and line feed (LF) in Linux and OS X. The new line sequence used depends on the operating system being used to write the code.

    [^\r\n]+ matches one or more characters that are not CR or LF characters. If a carriage return (\r) is encountered, the regular expression engine stops. Ditto for a line feed (new line or \n) character.

    Parentheses are used to create backreferences. In this case, they tell the engine to save all of those characters matched by [^\r\n]+ as a backreference. The backreference is retrieved via the JavaScript match method, which returns an array of results. The first item in the array ([0]) is the full match (including "Incident Title: "; this result isn't needed), and other items are added for each backreference. There's only one backreference, so the second item in the array ([1]) is the information you need.
    For every complex problem, there is an answer that is clear, simple, and wrong.

  2. Users who have thanked Arbitrator for this post:

    narelle (07-28-2013)

  3. #17
    New Coder
    Join Date
    May 2013
    Posts
    24
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Aha, my googling had help me come up with a little explanation, but I got stuck with the back referencing and wondering what the difference between \r and \n was.

    Thanks so much!


 
Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •