For more information about regular expressions, see [attach] 15627 [attach] for a specific field in the database. to retrieve the numbers in the tag, share the regular expressions with an example: regular expressions
Take a certain part of a field in the database, [attach] 15627 [/attach]. I want to extract the numbers in the tag and use regular expressions to give an example.
Share:
------ Solution --------------------
$ S = 'the [attach] 15627 [/attach] ';
Preg_match ('# \ [^ \] + \] (\ d +) \ [#', $ s, $ m );
Echo $ m [1];
------ Solution --------------------
Echo preg_replace ('# \ [([^ \] +) \] (\ d +) \ [/\ 1 \] #', '', $ s );
------ Solution --------------------
1: \ [match [. because [is a metacharacter, it must be escaped by a backslash.
2: ([^ \] +) match Non-] Symbols once or multiple times
\]: Similar to 1
(\ D +): \ d matches numbers
\ 1: it is called reverse reference. it is used in the same expression to match the content matched by the first sub-group.
You can read this blog post to learn about regular expressions:
Http://www.cnblogs.com/baochuan/archive/2012/03/12/2391135.html
------ Solution --------------------
Post the error message