What is a boundary (b) in a regular expression?

14

A long time ago, I took a look at using boundary , studying about regular expressions in PHP (PCRE Patterns).

I came across the \b (which is called boundary).

How useful is it in a regular expression?

    
asked by anonymous 30.01.2016 / 20:12

1 answer

22

The \b (beta) is an anchor as well as its ^ (alpha) and $ (omega) primes. Once added on one side of the regex will capture pattern specified at the beginning, end or exact , that means that it is valid only for letters, numbers and the underline (% with_%) which is the equivalent to [A-Za-z0-9_] .

Entry:

dialogo dia melodia diafragma dialeto radial bom-dia

Collapse at the beginning \w capture strings that contain at the beginning (not the beginning of the line ) the default \bdia , the items that enter the capture are, day logo, day , day fragma, strong> leto and bom- day

Anchor at the end dia captures strings (words) where the specified pattern is at the end, the captured items are: day , day and day

Extent anchor dia\b captures strings day and good - day

References

link

link

    
30.01.2016 / 21:33