Help with regex

Post a reply


In an effort to prevent automatic submissions, we require that you complete the following challenge.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Help with regex

Re: Help with regex

Post by brandonhotkey » 27 Jan 2014, 11:14

I have solved the problem. I created new patterns to fix my text:

Code: Select all

(?:[^cdkprmt])oje[tl].?
(?:[^cdkprmt])ojed[ueo][usm]?
To see more pls visit:
http://forums.phpfreaks.com/topic/28568 ... -badwords/
There are the sentences to be filtered in colors (red color is non working result).

I think bounderies would not help, the text in which I search is has no space.

Re: Help with regex

Post by sinkfaze » 27 Jan 2014, 09:36

Sounds like you need to deploy word boundaries:

Code: Select all

list=vojet,ojet,vojel,ojel,ojeli,dojel,dojeli,tojetvoje,tvoje

Loop, parse, list, `,
	if	RegExMatch(A_LoopField,"\bv?oje(?:t|li?)\b")
		MsgBox, %A_LoopField% is naughty naughty!
return

Help with regex

Post by brandonhotkey » 26 Jan 2014, 07:46

Hello. I am working on PHP project, there I use regular expresion search to find (bad)words which should be masked with stars. The characters which are match should be masked. Now I look dor regex for this particular situation:

I have a filter for filtering badwords in my native language. My language is very accurate not like simple English, so it is harder to give good exaple in English. I don't find good word / verb to have good example. But I will try.

I separated the pattern for three parts: prefix, middle and suffix. The middle will not change. The suffix can change. The prefix can be a specific letter or may not be present.


lets give example now:

Let's have the middle part: mil.

I want to find words like smile, smiles, smiling or mile, miles, miling

but not words like mill, mills, milling or words with different prefix like s. Here I dont find realistic example. So if there would be words like emile, emiles, emiling, amile, amiles, amiling, and so on. There could be also prefixes like pre-, un,- and so on. These words have not to be included in the result.



In my native language I tried something similar:

\bv?ojet.?\b

where ojet is the middle part and v is the only possible prefix. But this this not find anything.

My second try was

[v^d]?ojed[ueo][usm]

this time with different middle word: ojed. The suffix is changing here according declination. But always this does not work.

In my language the word would be either ojet in words like vojet,ojet,vojel,ojel,ojeli or in the second pattern it would be vojedu,vojedes,vojedem, and so on. These should be found and filtered. But there are next similar words which should not be in the result and not to be filtered: dojel,dojeli, kojeni, tojetvoje, tvoje, . So if the prefix is different than "v" it should not be found. Especially the last example is very problematic. Notice that is does not contain t or d on the preffix. So if "oje" from the "tvoje" string is selected, so this is wrong.


The common problem in my tests were that some of the characters of the incorrect middle word were captured. And I need only to capture the character of the correct word, in English example it is the mil, or smile, or smil... etc. So how can I specify pattern, that will capture as many characters as possible from the correct word, but not to capture the characters which are not presend.



Note:

I work only with a-z (small characters) no white characters in the text.

Top