T
T
turik_0072018-08-15 20:39:46
Regular Expressions
turik_007, 2018-08-15 20:39:46

Finding a character at a specific position in a string using a regular expression?

What does a regular expression look like, for example, for the following task:
find strings that do not contain the characters 'b', 'c', 'd'; there will be at least one 'a' in the entire string, except for the second position.
For example, the strings: 'aeghjk', 'aeaaasf' will match,
but the strings 'qwerty', qberty', 'q a sdfg' will not. In the last line 'a' in the second position in the line

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2018-08-15
@turik_007

Something like this:
^([^bcd][^abcd][^bcd]*a[^bcd]*|a[^abcd][^bcd]*)$

S
Saboteur, 2018-08-16
@saboteur_kiev

^(a[^abcd][^bcd]*|[^abcd]{2}[^bcd]*a[^bcd]*)$
By the way, it's funny that regex101 did not cope with this regexp.
https://regex101.com/r/PSr5s6/1/
although it actually works.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question