Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any word containing only alphabet , numbers but not Q, I, O , no other character

Tags:

python

regex

I am writing a program to match string with alpha numeric.I have tried on but could not find. please tell me regular expression for alphanumeric except o, O, I, i

i have tried many , but some times one character failing, i am new to regex

[A-HJ-NPR-Za-hj-npr-z0-9]$

My requirements are:

  • Takes all alphabet and number
  • Need to exclude Q, O and I small and capital
like image 624
Notepad Avatar asked Jul 04 '13 10:07

Notepad


2 Answers

You can try this:

/[^\Wqoi]*/i
  • [^\W] is same as \w - will take all alphanumeric characters..
  • So, [^\Woi] is same as \w - [oi]
  • /i flag is for case-insensitivity.

Since you don't want to match underscores, the correct regex would be:

/[^\Wqoi_]+/i

Since, \w also include _.

like image 124
Rohit Jain Avatar answered Oct 12 '22 10:10

Rohit Jain


This should work:

/\b(?:(?![qoi_])\w)+\b/i

Live Demo: http://www.rubular.com/r/ZbdKGOzyQg

like image 20
anubhava Avatar answered Oct 12 '22 11:10

anubhava