Note that there are some explanatory texts on larger screens.

plurals
  1. PORecusive sort of Regular Expression
    primarykey
    data
    text
    <p>I'm trying to build a regular expression where I been asked to filter string like</p> <p><code>country:India provinces:Uttranchal city:Dehradun zip_code:12345</code></p> <p>from the string like this </p> <p><code>keyword: one two three country:India provinces:Uttranchal city:Dehradun zip_code:12345 filter: myparameter</code></p> <p>Now I have prepared a basic regex like</p> <pre><code>country:\w+|provinces:\w+|city:\w+|zip_code:\w+ </code></pre> <p>Which sort of does the work for me If <code>country</code>,<code>provinces</code>,<code>city</code> are single words</p> <p>But if they are not example</p> <p><code>keyword: one two three country:United-States provinces:Manhattan city:New-York zip_code:12345 filter: myparameter</code></p> <p>The above reqex just not work because of the limitation of non word character like <code>-</code></p> <p>You can assume that the country,province or city and have word that join by many <code>-</code></p> <p>like</p> <p><code>country:United-States-of-America provinces:Washington-Dc city:New-York-West</code> </p> <p><strong>etc etc ...</strong> </p> <p>so <code>-\w+</code> is kind of recursive pattern with 0 or more occurence in either <code>country</code>,<code>provinces</code>,<code>city</code> or all of them </p> <p>Now I also tried build a regex for the same something like this</p> <p><code>(country:\w+(-\w+)*)|(province:\w+(-\w+)*)|(city:\w+(-\w+)*)|(zip_code:\w+(-\w+)*)</code></p> <p>This although matches but as you can see in rubular <a href="http://i49.tinypic.com/2qjxhcj.png" rel="nofollow">screenshot</a> attach that it also presented non accepted output and nil</p> <p>all I want is to avoid the <code>non-accepted</code> and <code>nil</code> output which causes problem in match result when segregating the desired string from the given input string or can somebody suggest me better regex than this</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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