Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: basic regex help please

by cfreak (Chaplain)
on Jan 05, 2005 at 17:09 UTC ( [id://419669]=note: print w/replies, xml ) Need Help??


in reply to basic regex help please

You can't specify the number of something in a character class (the brackets, which I assume you meant to put but Perlmonks snarfed them. Try using >code< tags next time :) ). But you are on the right track. This should do what you want:

/^(?:[0-9a-zA-Z]|\-{2,})/

I'm assuming you want ^ to match the beginning of the line. You don't put that inside the brackets unless you want to match a literal ^. Also note the \-{2,}. The comma is nessicary because it specifies that you want 2 or more hyphens. Just a 2 and it would look for exactly two hyphens. (if that's what you want then remove the comma).

I used ?: to keep the parenthisis from capturing the match, saves a little memory. You could take it out if you want to capture it for some reason.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-25 04:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found