|
I want to be able to use the content of a database table as part of a regex expression. This isn't the actual use case, but it shows what I want to do.
Database table includes a field with customer names, "Acme","Starbucks","Delta". This table gets updated with new customers daily.
I have a simple RegEx that looks for the existence of some text in an OCR'd document. (?i)(Acme|Starbucks|Delta)
I want to update the RegEx statement with the new entries. I know I can do it through some external scripting, but what I would like to do is embed some sort of call to the table and column a the time of execution, like "(?i)(ODBC Hook to the data here)"
|
|
|
|
|
Assuming that the regex engine you are using supports the dotall operator, you can use the following:
'\*\*\* START FAILSAFE \*\*\*\*\*\*\*\*\*(.*?)'\*\*\* STOP FAILSAFE \*\*\*\*\*\*\*\*\*\* Alternatively, you could use
'\*\*\* START FAILSAFE \*\*\*\*\*\*\*\*\*[\w\W]*?'\*\*\* STOP FAILSAFE \*\*\*\*\*\*\*\*\*\*
|
|
|
|
|
I am having a text file having some text to be remove enclosed within a defined tag (234 in the example below). This to-be removed text is not fixed and can occur multiple times in a single line OR can be spanned across multiple lines.
Example -
aaaaaaaaaaa234textA234aaaaa
234text234
blank line
bbbbbb234textB234bbbbbb
ccccc234te
xtC234
dddd234TextD234dddd
With this expression- "(\d)([\s\S]*?)(\d)", I am able to find out and replace the text with "" as expected but the problem occurs wherein the line ends with the tag (234) and the same line either starts with the tag (234) or in the continuation to the previous line like lines 2 and 6 in the above example. The problem is, line 2 and 6 are leaving a blank line behind and so the output contains 7 lines while I am expecting 5 lines (line 2 and 6 should be removed) only.
Please suggest.
|
|
|
|
|
I'd use a text (file) editor and do a replace all.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Hi,
I'm trying to figure how to 'find and replace' a textstring within a textfile. But the find and replace within the file has to only start after a certain textstring and it also has to stop before a second textstring. Can that be done with regex? Or would that require code (Python for instance).
Kind regards,
Roland
|
|
|
|
|
(?!^.*((Practice)|(ARCHIVE)|(CpSystem)|(RESTORE)).*$)(^\s*\w*)
Want to make Practice, Archive, CPSystem, and Restore case insensative.
I tried
(?i)(?!^.*((Practice)|(ARCHIVE)|(CpSystem)|(RESTORE)).*$)(^\s*\w*)
And
(?!^.*((?i)(Practice)|(?i)(ARCHIVE)|(?i)(CpSystem)|(?i)(RESTORE)).*$)(^\s*\w*)
Neither worked.
Any advise?
D
|
|
|
|
|
|
I have an alias.txt file that looks like this
CHALET_HIST_ARCHIVE - zz** Chalet History Archive **zz
CHALET_Practice - CHALET Retail ***Practice***
CHALET - CHALET
CPPractice - ***NCR Practice***
LANDSCAPE_Practice - CHALET Landscape ***Practice***
LANDSCAPE - CHALET LANDSCAPE
THALMANN - Thalmann Farm
CpSystem - CPSQL System Database
The value to the left of the dash is the alias name. I need to return all alias names that do not contain PRACTICE, ARCHIVE, RESTORE, or CPSYSTEM (regardless of case).
In the list above, the only valid values returned would be THALMANN, CHALET, and LANDSCAPE. All the others should be ignored as containing one of the above words to eliminate the result.
No white space before or after the returned value.
Currently i am at:
^\s*\w*
Which accurately includes everything left of the dash, but does not eliminate the above results containing one of the four words.
Any advise?
Dj
modified 20-Dec-21 12:16pm.
|
|
|
|
|
|
Hi!
Could anyone pls help med with a regex that extracts row 3 (Summer AB) only?
805
1506678441522
Summer AB
4302334
4302334
Structure
DBT.4302334"
|
|
|
|
|
I've a weird situation. I created a regex expression for one of the service. I've tested this expression at regexr.com and regex101.com and there are no problems at all. when I used this regex expression in fail2ban, it missed all the lines.
here is the log output;
[05-Oct-2021 17:09:39 +0300]: IMAP Error: Login failed for xyz@xyz.com against localhost from 95.65.143.88. AUTHENTICATE PLAIN: Authentication failed. in /usr/share/roundcube/program/lib/Roundcube/rcube_imap.php on line 204 (POST /webmail/?_task=login&_action=login)
here is the regex;
(IMAP Error: Login failed for)\s([a-zA-Z0-9_.-]+\@[a-zA-Z0-9_.-]+)\s(against localhost from)\s
is fail2ban using a different regex structure?
|
|
|
|
|
|
fail2ban is checking application logs and prevent intruders.
|
|
|
|
|
fail2ban regexes are a bit "different", particularly with the new(ish) prefixes and interpolations.
Your best bet is to use "fail2ban-regex".
Somewhere around the fail2ban site there is a tutorial about iincremental development of regexes.
It's a bit outdated, but the process works.
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
yep I'm using fail2ban-regex but before that I'm preparing my expressions at regexr.com.
|
|
|
|
|
My experience with fail2ban regexes is that they are sufficiently different from the "standard" ones that the regular development/test tools don't help.
I think you're stuck with fail2ban-regex, a dummy log file with examples of good and bad entries, and a whole lot of panel-beating, depending on how complex your requirements are.
It's worth looking at the various filter files provided with fail2ban. I found some helpful constructs in ones I don't actually use.
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
f2b should have provided standard regex expressions, so people wouldn't need to learn something else.
|
|
|
|
|
Hi,
im relatively new to regex and im trying to match OU from the Distinguished Name in ActiveDirectory.
This is my existing regex:
(((OU=.*?))?)OU=(?<ouname>.*?(?=,))
CN=Muster\, Max,[OU=AAD-Sync,OU=IT-Abteilung],[OU=FD] 10,DC=landkreis-Musterstadt,DC=local
So far this would match the OU I marked with [] as two separate Matches, does anyone know ow to edit my existing regex that it matches every OU as one Match instead of two separates?
Would be lovely if I could get some Help 
|
|
|
|
|
I have this regex to replace accents but it fails if the text contains "|".
string Text = "word|word2";
System.Text.RegularExpressions.Regex replace_a_Accents = new System.Text.RegularExpressions.Regex("[á|à|ä|â]", System.Text.RegularExpressions.RegexOptions.Compiled);
System.Text.RegularExpressions.Regex replace_e_Accents = new System.Text.RegularExpressions.Regex("[é|è|ë|ê]", System.Text.RegularExpressions.RegexOptions.Compiled);
System.Text.RegularExpressions.Regex replace_i_Accents = new System.Text.RegularExpressions.Regex("[í|ì|ï|î]", System.Text.RegularExpressions.RegexOptions.Compiled);
System.Text.RegularExpressions.Regex replace_o_Accents = new System.Text.RegularExpressions.Regex("[ó|ò|ö|ô]", System.Text.RegularExpressions.RegexOptions.Compiled);
System.Text.RegularExpressions.Regex replace_u_Accents = new System.Text.RegularExpressions.Regex("[ú|ù|ü|û]", System.Text.RegularExpressions.RegexOptions.Compiled);
Texto_Retorno = replace_a_Accents.Replace(Texto_Retorno, "a");
Texto_Retorno = replace_e_Accents.Replace(Texto_Retorno, "e");
Texto_Retorno = replace_i_Accents.Replace(Texto_Retorno, "i");
Texto_Retorno = replace_o_Accents.Replace(Texto_Retorno, "o");
Texto_Retorno = replace_u_Accents.Replace(Texto_Retorno, "u");
|
|
|
|
|
Why would you use a Regex for something so simple?
bool replacedAny = false;
char[] characters = Texto_Retorno.ToCharArray();
for (int index = 0; index < characters.Length; index++)
{
switch (characters[index])
{
case 'á':
case 'à':
case 'ä':
case 'â':
{
characters[index] = 'a';
replacedAny = true;
break;
}
case 'é':
case 'è':
case 'ë':
case 'ê':
{
characters[index] = 'e';
replacedAny = true;
break;
}
case 'í':
case 'ì':
case 'ï':
case 'î':
{
characters[index] = 'i';
replacedAny = true;
break;
}
case 'ó':
case 'ò':
case 'ö':
case 'ô':
{
characters[index] = 'o';
replacedAny = true;
break;
}
case 'ú':
case 'ù':
case 'ü':
case 'û':
{
characters[index] = 'u';
replacedAny = true;
break;
}
}
}
if (replacedAny)
{
Texto_Retorno = new string(characters);
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
modified 16-Sep-21 10:54am.
|
|
|
|
|
|
Nothing to see here. :innocent-whistle-smily:
In my defence, "3" is directly above "e" on the keyboard.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Given some of the nonsense that appears when I type too fast I think you do very well.
|
|
|
|
|
I was dreading it, Regex doesn't do the job and doesn't replace either?
|
|
|
|
|
Regex can do the job. But running five+ separate regex operations on a string just to replace a few letters with their unaccented alternatives is overkill.
The other option, which is even nastier and less obvious, is to use Unicode normalization:
static string RemoveDiacritics(string stIn)
{
string stFormD = stIn.Normalize(NormalizationForm.FormD);
StringBuilder sb = new StringBuilder();
for(int ich = 0; ich < stFormD.Length; ich++)
{
UnicodeCategory uc = CharUnicodeInfo.GetUnicodeCategory(stFormD[ich]);
if (uc != UnicodeCategory.NonSpacingMark)
{
sb.Append(stFormD[ich]);
}
}
return sb.ToString().Normalize(NormalizationForm.FormC);
}
string input = "Príliš žlutoucký kun úpel dábelské ódy.";
string result = RemoveDiacritics(input); Source[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|