LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Need help with this regex '^\*\|local7.*\s*\/[a-z]*' (https://www.linuxquestions.org/questions/linux-newbie-8/need-help-with-this-regex-%5E%5C%2A%5C%7Clocal7-%2A%5Cs%2A%5C-%5Ba-z%5D%2A-946508/)

blueskynet 05-23-2012 02:03 PM

Need help with this regex '^\*\|local7.*\s*\/[a-z]*'
 
Hi there,
As the title says, can someone explain to me what does that regex do? If possible, I would like to understand what each of these does.
\*

\|local7

.*

\s*

\/

[a-z]*

Thank you very much!

Tinkster 05-23-2012 02:58 PM

Can you please give us some context? Where did you dig this up, which tool/language
was it in? While 'regex' is a fairly well-known concept just about any tool you
touch that uses regex' will have a slightly different implementation.

If I assumed that the above was out of e.g., a perl snippet I'd break it up like so,
and would have to say that it's a weird (poorly written) regex:

Match anything that is either

Beginning of line, followed by any number of '\' followed by a backslash (the one behind the * doesn't make sense).
Code:

^\*\
or
Code:

|
the string local7 followed by any number of anything followed by any number of whitespace
followed by \/ followed by any number of lower case characters.
Code:

local7.*\s*\/[a-z]*

All up it makes little sense.



Cheers,
Tink

chrism01 05-23-2012 07:04 PM

Quote:

While 'regex' is a fairly well-known concept just about any tool you
touch that uses regex' will have a slightly different implementation.
Absolutely(!); check out this book for details http://regex.info/blog/2006-07-21/218.
I've read it a couple of times; very good.

grail 05-24-2012 08:16 AM

As the other's have said, it will depend on where this came from and I will show you why, as this is how I interpreted it:

Code:

^      - start of the line / string
\*    - an asterisk, escaped so as not to be confused
\|    - a pipe, also escaped
local7 - string
.*    - zero or more of any character
\s*    - zero or more spaces
\/    - forward slash, escaped like others above
[a-z]* - zero or more lower case letters

As you can see, without reference the outcome is quite different to Tink's above.


All times are GMT -5. The time now is 07:03 PM.