Abstract
Hello everyone it’s me candle. In this time I would like to create a regular expression that does not pass if keywords that I do not want included in the string match.
This is such case like this. For example, the regex matches these words “Bitcoin” and “Bitcoin ~” but doesn’t match “BitcoinCash” and “Bitcoin Cash”.
○ Bitcoin
○ Bitcoin Core
× BitcoinCash
× Bitcoin Cash
Condition
Nothing
Write the regex
This is a regex that does not match if there are keywords that you do not want included in the string.
/Keyword to include(?!Keywords you do not want included)/
For example, if you want to match “Bitcoin” and “Bitcoin ~” and exclude “Bitcoin Cash” and “Bitcoin Cash”, it looks like this. |
OR and \s
space symbols are mixed.
reg = /Bitcoin(?!Cash|\sCash)/
This is the sample code.
name1 = "Bitcoin" name2 = "Bitcoin Core" name3 = "BitcoinCash" name4 = "Bitcoin Cash" reg = /Bitcoin(?!Cash|\sCash)/ if name1 =~ reg p name1 end if name2 =~ reg p name2 end if name3 =~ reg p name3 end if name4 =~ reg p name4 end
Conclusion
I think that it is really easy once you know a regular expression, but it will be quite hard before you figure it out.