Regex match function

I am looking for a function that will try to find and return everything that matches the regular expression \\(\\S-\\) and possibly nil if nothing was found. The search must begin with (point) and search at the end of the document.

+4
source share
1 answer

Use re-search-forward and match-string :

 (when (re-search-forward "\\(\\S-\\)" nil t) (match-string 1)) 

If you do not want the point to move, wrap it in save-excursion :

 (save-excursion (when ... 
+7
source

All Articles