Regular Expression help - Does (.) Mean new line?

  • Hi there

     

    I am re-writing some code which uses regular expressions

    Part of the code uses the following:

    ^(.){1,50}$'', 0)'

    Does this mean …. any character where the string is between 1 and 50 characters

    but the (.) means cannot contain newline?

    And does it mean no newline character at the beginning?

     

     

     

     

  • Have a look at this webpage:

    https://regex101.com/r/cO8lqs/2

    It lets you test out RegEx and it provides an explanation of what the regex is doing.

    Your understanding of that part is correct.  (.) is any character except new line, ^ is starts with and {1,50} means it can be between 1 and 50 characters long.  The $ means "asserts position at the end of the string, or before the line terminator right at the end of the string (if any)" so I am not entirely sure what your regex is doing with the '',0)' at the end, but I expect it not to find any matches ever as $ basically means "ends with" and applies to the characters before it.

    The above is all just my opinion on what you should do. 
    As with all advice you find on a random internet forum - you shouldn't blindly follow it.  Always test on a test server to see if there is negative side effects before making changes to live!
    I recommend you NEVER run "random code" you found online on any system you care about UNLESS you understand and can verify the code OR you don't care if the code trashes your system.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply