Note that there are some explanatory texts on larger screens.

plurals
  1. POFind all possible permutations of a lowercase chemical formula
    primarykey
    data
    text
    <p>I'm trying to resolve ambiguity in a lowercase chemical formula. Since some element names are substrings of other element names, and they're all run together, there can be multiple global matches for the same pattern.</p> <p>Considering the regex <code>/^((h)|(s)|(hg)|(ga)|(as))+$/</code> against the string <code>hgas</code>. There are two possible matches. <code>hg, as</code> and <code>h, s, ga</code> (out of order compared to input, but not an issue). Obviously a regex for all possible symbols would be longer, but this example was done for simplicity.</p> <p>Regex's powerful lookahead and lookbehind allow it to conclusively determine whether even a very long string does match this pattern or there are no possible permutations of letters. It will diligently try all possible permutations of matches, and, for example, if it hits the end of the string with a leftover <code>g</code>, go back through and retry a different combination.</p> <p>I'm looking for a regular expression, or a language with some kind of extension, that adds on the ability to keep looking for matches after one is found, in this case, finding <code>h, s, ga</code> as well as <code>hg, as</code>.</p> <p>Rebuilding the complex lookahead and lookbehind functionality of regex for this problem does not seem like a reasonable solution, especially considering the final regex also includes a \d* after each symbol.</p> <p>I thought about reversing the order of the regexp, <code>/^((as)|(ga)|(hg)|(s)|(h))+$/</code>, to find additional mappings, but at most this will only find one additional match, and I don't have the theoretical background in regex to know if it's even reasonable to try.</p> <p>I've created a sample page using my existing regex which finds 1 or 0 matches for a given lowercase string and returns it properly capitalized (and out of order). It uses the first 100 chemical symbols in its matching.</p> <p><a href="http://www.ptable.com/Script/lowercase_formula.php?formula=hgas" rel="nofollow">http://www.ptable.com/Script/lowercase_formula.php?formula=hgas</a></p> <p>tl;dr: I have a regex to match 0 or 1 possible chemical formula permutations in a string. How do I find more than 1 match?</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