Re: Regular expressions

new topic     » goto parent     » topic index » view thread      » older message » newer message
ChrisB said...

Hi

I have never used regular expressions before. I have used some simple greps.

Previously, if I have wanted to search a file for a particular string, I have opened and loaded the file, used find and match with each of the lines, and have not been unhappy with the speed or flexibility.

Should I instead be using the eu regex now? Is there an advantage to this for simple searches? One of the comments in the docs is that it is a large subjuct. Is there an advantage to me learning it?

Regular expressions probably won't be much of a benefit for simple searches. You're probably better off using the built in match() or find() functions. Regular expressions are more useful once you start using wildcards, or if you want to validate that data take a particular form.

For instance, suppose that I have some database records whose primary keys are all uuids, represented as lowercase text, without any dashes (this is an actual situation, BTW). To validate that I have a valid list of comma separated ids, I can use this expression:

  "^(?:[0-9a-f]{32},)+$" 
It verifies that each id is exactly 32 characters, is only numbers and lowercase a-f, and that it's followed by a comma. It also makes sure that there is no other text either before or after the list.

Matt

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu