When is it better to use regular expressions?

I'm starting to learn regular expressions, and I want to know: in what cases is it better to use them?

+5
source share
7 answers

Regular expressions are a form-matching form that you can apply to text content. Take for example DOS wildcards? and * that you can use when looking for a file, This is a kind of very limited subset of RegExp. For example, if you want to find all files starting with "fn", and then from 1 to 4 random characters and ending with "ht.txt", you cannot do this with the usual DOS wildcards. RegExp, on the other hand, can handle these and more complex patterns.

Regular expressions are, in short, a way to effectively

  • process data
  • search and replace strings
  • provides advanced line processing.

, , , , .

+7

// .

+4

(preg_match), (sed, preg_replace), (sed, preg_replace), (grep), (preg_split) ..

, .

! , , .

question, , , RegEx, .

+4

, , . CSV .

+2

dsl (, ) . , xpath - dsl xml. , , - . , . , , , ssn ..

+2

, → NOT < ( , ).

  • HTML
  • XML

DOM . , .

( ). / // , , .

+2

Regular expressions can be especially useful for checking free text input format. Of course, they cannot confirm the correctness of the data, namely their format. And you should keep in mind regional variations for certain types of values ​​(e.g. phone numbers or postal codes). But for cases where a valid input can be defined as a text pattern, regular expressions do a quick check job.

0
source

All Articles