Blog - Latest News

regular expression syntax in php

ExampleDescription
‘/hello/’It will match the word hello
‘/^hello/’It will match hello at the start of a string. Possible matches are hello or helloworld, but not worldhello
‘/hello$/’It will match hello at the end of a string.
‘/he.o/’It will match any character between he and o. Possible matches are helo or heyo, but not hello
‘/he?llo/’It will match either llo or hello
‘/hello+/’It will match hello on or more time. E.g. hello or hellohello
‘/he*llo/’Matches llo, hello or hehello, but not hellooo
‘/hello|world/’It will either match the word hello or world
‘/(A-Z)/’Using it with the hyphen character, this pattern will match every uppercase character from A to Z. E.g. A, B, C…
‘/[abc]/’It will match any single character a, b or c
‘/abc{1}/’Matches precisely one c character after the characters ab. E.g. matches abc, but not abcc
‘/abc{1,}/’Matches one or more c character after the characters ab. E.g. matches abc or abcc
‘/abc{2,4}/’Matches between two and four c character after the characters ab. E.g. matches abcc, abccc or abcccc, but not abc
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *