Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Re: Regex confusion

by neilwatson (Priest)
on Aug 07, 2002 at 16:54 UTC ( [id://188386]=note: print w/replies, xml ) Need Help??


in reply to Re: Regex confusion
in thread Regex confusion

So let's step back one square: what kinds of things are you trying to match?

Trying to match: client.project.subproject where:

  • Client and project are manditory. Subproject is optional but, there could be more than one.
  • Client, project and subproject could contain, letters, numbers, _, -, or \&
Does that help?

Update:Actually your regex /([^.]+)\.(\S+)/ works well. Thank you.

Neil Watson
watson-wilson.ca

Replies are listed 'Best First'.
Re:^3: Regex confusion
by flounder99 (Friar) on Aug 07, 2002 at 17:22 UTC
    OK, to match those possible characters (and only those) try something like
    m/((?:\w|\\\&|\-)*)\.((?:\w|\\\&|\-)*)/
    the \w takes care of letters, numbers and _. I always escape the - out of habit but is unnecessary. The /i is redundant since the \w is case insensitive.
    Personally I would do a nongreedy match. It will match other characters but it probably won't matter. Something like:
    m/(.*?)\.(.*)/
    update -- of course a simple split would do the trick.
    my ($client, $project, $subproject) = split /\./, $x;

    --

    flounder

      update -- of course a simple split would do the trick.

      Neil bangs his head vigourously against his desk. Of course! Why the hell didn't I think of that before?

      Thank you all for your input.

      Neil Watson
      watson-wilson.ca

Re: Re: Re: Regex confusion
by graff (Chancellor) on Aug 07, 2002 at 17:39 UTC
    Arturo is right -- I don't see how anything is getting assigned to $project, since the match does not succeed at all for the initial example.

    Trying to match: client.project.subproject where:

    • Client and project are manditory. Subproject is optional but, there could be more than one.
    • Client, project and subproject could contain, letters, numbers, _, -, or \&

    Update:Actually your regex ... works well. Thank you.

    Arturo's regex will include both your project and all sub-projects in $2. If that's okay, fine. If not, do it like this:

    /([^.]+)\.([^.]+)/

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://188386]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-18 02:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found