Note that there are some explanatory texts on larger screens.

plurals
  1. POMatch first word of a phrase in a String
    primarykey
    data
    text
    <p>I am using the GTMRegex class from the Google toolbox for mac (in a Cocoa / Objective-C) app:</p> <p><a href="http://code.google.com/p/google-toolbox-for-mac/" rel="nofollow noreferrer">http://code.google.com/p/google-toolbox-for-mac/</a></p> <p>I need to do a match and replace of a 3 word phrase in a string. I know the 2nd and 3rd words of the phrase, but the first word is unknown.</p> <p>So, if I had:</p> <p>lorem BIFF BAM BOO ipsem</p> <p>and</p> <p>lorem BEEP BAM BOO ipsem</p> <p>I would watch to match both (BEEP BAM BOO) and (BIFF BAM BOO). I then want to wrap them in bold HTML tags.</p> <p>Here is what I have:</p> <pre><code>GTMRegex *requiredHeroRegex = [GTMRegex regexWithPattern:@"(\\([A-Z][A-Z0-9]*)\\b Hero Required)" options:kGTMRegexOptionSupressNewlineSupport|kGTMRegexOptionIgnoreCase]; out = [requiredHeroRegex stringByReplacingMatchesInString:out withReplacement:@"&lt;b&gt;\\1&lt;/b&gt;"]; </code></pre> <p>However, this is not working. basically, I cant figure out how to match the first word when I dont know it.</p> <p>Anyone know the RegEx to do this?</p> <p>Update:</p> <p>GTRegEx uses POSIX 1003.2 Regular Expresions, so the solution is:</p> <pre><code>GTMRegex *requiredHeroRegex = [GTMRegex regexWithPattern:@"([[:&lt;:]][A-Z][A-Z0-9]*[[:&gt;:]])( Hero Required)" options:kGTMRegexOptionSupressNewlineSupport|kGTMRegexOptionIgnoreCase]; out = [requiredHeroRegex stringByReplacingMatchesInString:out withReplacement:@"&lt;b&gt;\\1\\2&lt;/b&gt;"]; </code></pre> <p>Note the crazy syntax for the word boundaries.</p> <p>Update 2 : Here is the JavaScript version:</p> <pre><code>/(([A-Za-z]*?|[A-Za-z]*? [A-Za-z]*?)( Hero Required))/gm </code></pre>
    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