Regular expression: How to choose something that matches the beginning or end, but is not both?

I have this situation: the regular expression is like this:
^ b? A b? $

So b can match at the beginning of the string 0 or 1, and A must match one or more times. Again b can match 0 or 1 times at the end of the string.

Now I want to modify this regular expression in such a way that it can match b at the beginning or end of the string, but not b at the same time.

What should I do?

You can use a beautiful “or” operator in regexp.

^(b?A+|A+b?)$

I have this situation: the regular expression is like this Of:
^ b? A b? $

So b can match at the beginning of the string 0 or 1, and A must match one or more times. Again b can match 0 or 1 times at the end of the string.

Now I want to modify this regular expression in such a way that it can match b at the beginning or end of the string, but not b at the same time.

What should I do?

You can use a beautiful “or” operator in regexp.

 ^(b?A+|A+b?)$

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 5477 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.