Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Regex | Find 3 character length word starts with specific char '%'

Using Regex, I need to find a word within a encoded url query string which matches start with specific char % and word must be 3 chars length long including starting specific char %.

A sample is following:

Sam+JS%2C+COSP+Lepar-+Happy+Search+%28ENG%29+%5B320kbps%5D+%5B2019%5D+%7BYMB%9D

First char would always be %

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Second char would always be a number [0-9]

Third char would be either a number OR an alphabet (either in small or caps)

Result from above sample like be:

%2C %28 %29 %5B %5D %5B etc..

Hope problem is very clear.

>Solution :

Your regex should be something like that

['%']{1}[0-9]{1}[a-zA-Z0-9]{1}

Explain the code:

['%']{1} => matches the character %
[0-9]{1} => matches a single character in the range between 0 and 9
[a-zA-Z0-9]{1} => matches a single alphabet character or number between 0 and 9

You could build and test regex on regex101
enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading