<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>;This I understand:<br>
</div><div>;To return pattern and everything to left of first instance of pattern, use: [^<pattern>]*<pattern> ;where ^ means 'not'; example:<br>
(car (regexp-match* #rx"[^/]*/" "12/4/6")) ; => "12/"<br></div></div></blockquote><div><br></div><div>A caveat for this. <pattern> in the first instance isn't quite right. [...] defines a single character. [abc] for example, means a, b, or c. The ^ negates the pattern, so [^abc] means anything a, b, or c. Then * means match the proceeding pattern 0 or more times. So [^abc]* means any number of a, b, or c in any order (if you want repeating "abc", you want paranthesis: #rx"(abc)*"). The entire point though is that if you wanted to match something like this: "12abc34abc6abc7", using #rx"[^abc]*abc" wouldn't work. Instead of 'not abc than abc', you're getting 'anything not a or b or c then abc' You'd need something a bit more complicated.<br>
</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>;This I do not understand: <br></div><div>;To return pattern and everything left of first instance of pattern, use: .*?<pattern> inside #rx""; where ? means _______; or where .*? means ______________; example:<br>
(car (regexp-match* #rx".*?/" "12/4/6")) ; => "12/"<br></div></div></blockquote><div><br></div><div>Technically, the interesting part there isn't .*? or just ?, but rather *? A single dot means to match any character. .* means to match any number of characters. The problem with that is * by default is greedy. It will match the longest sequence it can. Since . is anything, the pattern #rx".*/" on "12/4/6" will match 'the longest string of any character followed by a /' that it can: "12/4/". If you instead want a non-greedy (lazy) match, use *? or +? instead of * or +. That says, match the proceeding pattern until the next pattern matches. So it will match 'any character until a / is seen', so "12/".<br>
<br></div><div>It doesn't particularly help that ? also has a meaning by itself. It makes the previous pattern optional. So #rx"x?y" matches "y" or "xy". <br></div><div><br></div><div>Regular expressions are pretty amazingly powerful. This is a site I've found useful in the past for looking up what things mean:<br>
</div><div><a href="http://www.regular-expressions.info/">http://www.regular-expressions.info/</a><br><br></div><div>Specifically for more information on repeating patterns (* + *? +?):<br><a href="http://www.regular-expressions.info/repeat.html">http://www.regular-expressions.info/repeat.html</a><br>
<br></div><div>Hope that helps!<br><br>JP<br></div></div></div></div>