Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Something like this might do the trick:</p> <pre><code>/Seat (\d+): ([^\(]+) \((\d+)in chips\)/ </code></pre> <p>And some basic explanation on how Regex works:</p> <ul> <li><p>\d = digit.</p></li> <li><p>\&lt;character> = escapes character, if not part of any character class or subexpression. for example: </p> <p><code>\t</code> would render a tab, while <code>\\t</code> would render "\t" (since the backslash is escaped).</p></li> <li><p>+ = one or more of the preceding element.</p></li> <li><p>* = zero or more of the preceding element.</p></li> <li><p>[ ] = bracket expression. Matches any of the characters within the bracket. Also works with ranges (ex. A-Z).</p></li> <li><p>[^ ] = Matches any character that is NOT within the bracket.</p></li> <li><p>( ) = Marked subexpression. The data matched within this can be recalled later.</p></li> </ul> <p>Anyway, I chose to use </p> <pre><code>([^\(]+) </code></pre> <p>since the example provides a name containing spaces (Seat 3 in the example). what this does is that it matches any character up to the point that it encounters an opening paranthesis. This will leave you with a blank space at the end of the subexpression (using the data provided in the example). However, his can easily be stripped away using the trim() command in PHP.</p> <p>If you do not want to match spaces, only alphanumerical characters, you could so something like this:</p> <pre><code>([A-Za-z0-9-_]+) </code></pre> <p>Which would match any letter (within A-Z, both upper- &amp; lower-case), number as well as hyphens and underscores.</p> <p>Or the same variant, with spaces:</p> <pre><code>([A-Za-z0-9-_\s]+) </code></pre> <p>Where "\s" is evaluated into a space.</p> <p>Hope this helps :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload