For example i have lines:

* test1
** another tests
* some other line

I would like to match t in first line, a in second, s in third.

  • The title and the body of the question are inconsistent. Please edit to make them agree. Do you want the first character which is "not * and not whitespace" or do you want the first character "after certain other character"? Those are completely different requierments. – phils Mar 18 at 22:06
  • Sorry. I added an example, to make my question more clear. – Sime1 Mar 19 at 16:26
(re-search-forward "[^*[:space:]]")

Then use match-data or similar functions, if you want the match.

And put that code inside save-excursion if you don't want to end up moving the cursor.

If you want to include newline chars as whitespace chars then use something like

| improve this answer | |
  • 1
    Your code matches all characters in line that are not * or spaces. I just want to match 1 - the first one that is not * or space. btw im using regex for avy command. – Sime1 Mar 18 at 20:02
  • No, it matches the first such character. – Drew Mar 18 at 21:19
  • 1
    @Sime1 If the issue is specific to avy, then please ask a separate new question about avy. – phils Mar 18 at 22:04

Emacs regexps don't have arbitrary zero-width look-around assertions, so if you're hoping for a pattern which in its entirety would only ever match those characters (no matter where it started from, or how many times you searched) then you're out of luck. In Emacs such behaviours are achieved using elisp rather than solely with the regexp engine.

You can, of course, search for:

^\*+ \(.\)


"^\\*+ \\(.\\)"

And then you'll have the character you wanted in the matched sub-group.

It all depends on what you're doing, though.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.