Search the Community
Showing results for tags 'regex'.
-
I need a regular expression for this shortcode [image file=name.ext] The shortcode is image and there will only be one attribute, file. Obviously there might be spaces either side of the equals sign and the name and ext can be a variable length made up of numbers, characters, dashes and underscores. Initially to keep it simple I only allowed numbers and letters in the name and ext and no spaces either side of the equals sign. I've tried several options but none are working. How do you represent the [ and ] in a regex. My attempts at escaping them with a double backslash haven't worked. Here's what I tried /^(//[image file=])+([\w.])+(\\]{1})$ I also tried using a single backslash to escape the brackets, but that didn't work either. Thanks for any suggestions.
-
I'm in the middle of Chapter 14, Perl-compatible Regular Expressions. On Page 444, the following pattern is offered to test for presence of non-whitespace characters in a string: ^\S$ If I'm interpreting the chapter correctly so far, in the form created for testing subjects against patterns, pcre.php, I should enter this code inside a pair of delimeters, like so: /^\S$/ So, I've done that, and typed a string into the subject text area: Testing for whitespace characters. I received FALSE, so far so good. Then I type simply: testing And I received FALSE again! Suspecting that I may have messed up the code of pcre.php, I replaced my file with the one I downloaded from Larry's website. Ran the same two tests again, received same results. Either I'm missing something, which I suspect is the case, or the pattern is incorrect. Could someone please explain to me how to make it work or what I'm doing wrong?