0

I am trying to learn regex and came across this question: Extract a substring between two characters in a string PHP for which one of the answers has:

    $input = "[modid=256]";
preg_match('~=(.*?)]~', $input, $output);
echo $output[1]; // 256

I am guessing ~=(.*?)]~ can be broken down into saying 'find the thing between = and ] ' but what do the ~ mean and how are they used in general? (I have looked in other places but can't seem to find a meaning for this symbol)

Community
  • 1
  • 1
  • It's called a tilde. Perhaps you did not know that when you were searching. Google tends to remove the weird characters in your searches, but if you write the word "tilde" I am sure you will find something. – Mad Physicist Mar 15 '16 at 19:45
  • @MadPhysicist Ye your right, actually I wouldn't have called that a tilde, I tend to associate tildes with things that go above letters rather then a stand alone character. – Quantum spaghettification Mar 15 '16 at 19:46
  • 1
    @Quantumspaghettification. I used to think that when I studied French. Now I study computers more, so my bar for what I consider to be a proper tilde has moved down. – Mad Physicist Mar 15 '16 at 19:48
  • The tilde is used to match in RegEx. The 2 operators '~' and '!~' perform regex comparisons. – philbrooksjazz Mar 15 '16 at 19:52

0 Answers0