Need a regex to validate 'earn an extra 20%' or 'earn an extra 20%'

王林
Release: 2024-02-09 13:33:09
forward
496 people have browsed it

需要一个正则表达式来验证“赚取额外 20%”或“赚取额外 20%”

php editor Xiaoxin will introduce you to a regular expression in this article, used to verify "earn extra 20%" or "earn extra 20%". Regular expressions are a powerful text matching tool that can be used to validate and extract strings in a specific format. This regular expression can help us find strings that meet specific requirements in a piece of text and process them accordingly. In this article, we will explain the composition and use of this regular expression in detail to help everyone better understand and apply it.

Question content

Need a regular expression to verify the string mentioned below.

'Earn extra 20%' - valid

'Earn 20% extra' - valid

'earn extra 20%' - valid

'earn 20% extra' - valid

'Earn 20' - valid

'Earn ' - Invalid

'20' - Invalid

'Earn ^&' - Invalid
Copy after login

No other special characters should be allowed

- Using golang 1.19

Workaround

Use (?i) (case-insensitive) alternation of flags and optional terms (instead of using go Lookaround not supported):

(?i)earn (\d+%?( extra)?|extra \d+%?)
Copy after login

See Live Regular Expression Demo.

See Live Demo.

The above is the detailed content of Need a regex to validate 'earn an extra 20%' or 'earn an extra 20%'. For more information, please follow other related articles on the PHP Chinese website!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!