Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Regex help

by strider corinth (Friar)
on Nov 16, 2002 at 13:59 UTC ( #213395=note: print w/replies, xml ) Need Help??


in reply to Regex help

You've got it almost right, from what I can see. Your post looks a little strange (you'll notice your brackets are missing) because PerlMonks uses brackets to make linking easier in posts (anything in brackets links to the node named whatever's within the brackets). In the future, you'll probably want to put <code> tags around any code you post.

From what I can see, your regexp looks like this: /^[A-Za-z0-9]/ There's only one small error- the ^ is outside of the brackets. A caret outside of brackets means 'match this regexp at the beginning of a string'. If you move it inside: /[^A-Za-z0-0]/ you should find that it does what you want it to.

Incidentally, there are two shortcuts you might be interested in. You can use the escape sequence "\w" to mean "match all alphanumeric characters plus '_'", and "\W" to mean "match everything but \w". So if it's ok for you to add "_" to the class of characters that are ok to find, the whole thing can be shortened to /\W/.

A good place to look for more information on this is the perlre man page. Happy Perling!
--
Love justice; desire mercy.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2023-10-04 03:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?