0

I am trying to write some string replace functions, and rather than ask how to do a specific replace, I want to know more about modifiers so I can do it myself

Take this for example:

preg_replace('~[\W\s]~', ' ', $input);

or

strlen(preg_replace('![^A-Z]+!', '', $s));

What are those called? (~[\W\s]~) (![^A-Z]+!) They make very little sense to read or make up a new one. Where can I find all of them? Or learn how to write them?

2
  • Those are called regular expressions Commented Oct 10, 2014 at 14:09
  • 1
    they're called regular expressions. They are extremely powerful, though a bit daunting at first. This is a good site to learn more about them. Note PHP uses PCRE regex's (Perl Compatible Regular Expressions) Commented Oct 10, 2014 at 14:09

1 Answer 1

2

They are called Regular Expressions. From http://www.regular-expressions.info , 'A regular expression (regex or regexp for short) is a special text string for describing a search pattern. You can think of regular expressions as wildcards on steroids.'

Here is a site with references and a playground to test working with them.

http://regexr.com

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.