Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Is your goal really to match every character in the ASCII character set except for 0-9 and _ (underscore)? I couldn't suggest a better alternative without knowing exactly what you want. However, again if you're only working with ASCII and not Unicode, these expressions do the same thing, in slightly different ways:

  • [A-Za-z\W] - Match A-Z, or a-z or any character that is not A-Z a-z, 0-9, _. This reduces to matching all characters that are not 0-9, _.
  • [^_\d] - Match any character that is not _ or 0-9. Much simpler way to state the previous expression.
  • (?!_)\D - Don't match if the next character will be an underscore, and don't match if that character is 0-9. This one uses look-ahead to check first if the next thing would not be _, then advances the position in the string and checks if the current thing is not 0-9. It uses lookahead, and then look at semantics.
  • \D(?<!_) - Don't match if the current character is 0-9. Also if that character was _ (underscore) fail to match. This checks the character at the current position, and then after advancing the marker in the string looks back to see that it was also not underscore. It uses look-at, and then lookbehind semantics.

Of these options the second one is certainly the easiest to read. But my point in my previous post was that I'm doubtful this is exactly what you want. It seems very suspect to allow matching \t, \n, (, ), ^, -, A, B, z, ' '(space), ','(comma), and so on, but to disallow any numeric digit and the underscore. It doesn't seem like it's doing what you want it to be doing. But you didn't make clear to me what it is that you actually want to do.

Furthermore, if you are dealing with Unicode semantics, the number of characters that are matched by that pattern is enormous, and even weirder. If you suggested what you're trying to match we might be able to help come up with a more specific expression.


Dave


In reply to Re^3: Function for reading file by davido
in thread Function for reading file by shabird

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found