Regular Expressions

6K

Solutions

7

Articles & Videos

5K

Contributors

A regular expression ("regex") is a sequence of characters that define a search pattern, mainly for use in pattern matching with strings, or string matching, i.e. "find and replace"-like operations. Regular expression processors are found in several search engines, search and replace dialogs of several word processors and text editors, and in the command lines of text processing utilities, such as sed and AWK. Many programming languages provide regular expression capabilities, some built-in, for example Perl, JavaScript, Ruby, AWK, and Tcl, and others via a standard library, for example .NET languages, Java, Python and C++ (since C++11). Most other languages offer regular expressions via a library.

Share tech news, updates, or what's on your mind.

Sign up to Post

I am trying to gather all of the characters following the final space in a string but am struggling with the syntax. Can anyone help please? The last set of characters will always be alphanumeric but will be of differing characters and amount of charaters.

In the below example I would only want to highlight cat.  

dog xxx-klsfkd-sdf-sdf cat


And in the next one aaaaaaaaaaaaaddddddddddddddd

heht ooijl-nanhjhsh aaaaaaaaaaaaaddddddddddddddd


Many Thanks
0
Technology Partners: We Want Your Opinion!
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Hi All,

Background:
I have written a script to grab the most common words in a page (with tags stripped etc.) It mostly works, however there is an occasional occurrence of the following happening: helloThisIsAnExampleOfTheAnomoly.

This occurs while grabbing certain HTML via a cURL based function, stripping tags and counting word frequency. It mostly appears to occur in menus and widgets.

What I'm looking for is an elegant/efficient solution to pop/push/unset values in the array with the values split.

To expand:
preg_replace('/(?<! )(?<!^)[A-Z]/',' $0', $words)

Open in new window


I'm using the above regular expressions to essentially split the values based on uppercase values occurring mid string/array element.

To summarise:
$array is currently something like this: ("This", "is", "okay", "this", "IsNotOkay")
What I want:
$array is going to look something like this ("This", "is", "okay", "this", "Is", "Not", "Okay")

Don't worry too much about the repeat values as I am utilising a "stop words" array to rid the ones I would not like to keep.

I've not got it working nicely yet so thought I'd turn to you for your expert input.

Thanks in advance.
Chris
0
I am looking to replace the value between two spaces in a string with a backslash. Can someone assist with the syntax.

E.G. I want

RED 123456789 White

to become

RED\White

Thanks
0
Hi

I'm trying to create a template  using a REGEX rule to discard the last twenty four characters (" action=allow cache=MISS") of the following string when RSYSLOG receives notifications that contain the undesired sequence:
192.168.22.167 GET http://clients3.google.com/generate_204 action=allow cache=MISS

Open in new window

I can select the sequence using /( action=allow cache=MISS)/g but I can't find the solution to invert the selection in order to retain only the first part of the notification message
any ideas ?
thanks
yann
0
Hi I have a regex which works fine on

ABCDE123456X  - /LYBLA[0-9]{6}X/i (Fixed ABCDE, followed by 6 digits, and a fixed X.

I need to change this to be able to use a 7th digit instead of the final fixed X as well as the original format, for example

ABCDE1234567 and ABCDE987654X

Please advise
0
I have a form w/ several fields...one of the fields requirements states: The Contract Number is required and can contain no more than 22 alphanumeric characters. This can't contain spaces however:

here's the current regex setup:

	, Contract_Number: {
				required: true
			   ,pattern: /^[DdFfGgHhNnVv][A-Za-z0-9]*$/

Open in new window


Does anyone have any suggestions on how to modify this?
0
I need to pull two values from a repeating string. I've got it working 99% but it's ugly.

Looking for a trick here if you see one.

/******************************************
I got a simple solution, see comments
leaving here for any tips you might have
******************************************/

I am using REGEXP_COUNT to determine I have repeating strings, but that doesn't help me with the string manipulation.

Here's the data, it's a varchar2(600),
ATTENDED ECOLE NAVALE/FRANCE AS AN EXCHANGE STUDENT, SPRING '09
RECEIVED A LANGUAGE STUDY MINOR IN FRENCH
RECEIVED A LANGUAGE STUDY MINOR IN SPANISH

RECEIVED A LANGUAGE STUDY MINOR IN JAPANESE
RECEIVED A LANGUAGE STUDY MINOR IN CHINESE

ATTENDED NOVAMOVA, KIEV, FALL 2014 AS AN EXCHANGE STUDENT.
RECEIVED A LANGUAGE STUDY MINOR IN ARABIC. RECEIVED A LANGUAGE STUDY MINOR IN RUSSIAN.

RECEIVED A LANGUAGE STUDY MINOR IN RUSSIAN
RECEIVED A LANGUAGE STUDY MINOR IN SPANISH

RECEIVED A LANGUAGE STUDY MINOR IN ARABIC
RECEIVED A LANGUAGE STUDY MINOR IN SPANISH

For the first values, I get
FRENCH R
JAPANESE
ARABIC. R
RUSSIAN
ARABIC R

Here's my code -
The "9" is the length for the first value, to get the proper length would make this even uglier
The "+8" just points me in position to find the second value

Just showing how ugly it is. The only issue is getting the firs value cleanly.

     
substr(tn.notes, 
              -- find the position where the first minor starts
              

Open in new window

0
I want to match a url  such that it allows "abc.def.com" but not allow the following:
"abc.def.com/123"
"abc.def.com/456/789"

Thanks
0
Hi I need to parse the content between the first and second '-' in a string, ie  012-09324-5418567  (Oracle 10g)
The following does work for me; however, I was also wondering if there is a more efficient way to do this or how to do it using regexp_instr:
 
SELECT SUBSTR('012-09324-541',INSTR('012-09324-541', '-')+1, INSTR('012-09324-541', '-' ,1,2)-INSTR('012-09324-541', '-')-1) FROM DUAL;

Open in new window


Result:  09324
 
Thank you in advance for suggestions.
0
my regular expressions isnt' working...need one  for a POC form field that can include alphabetic characters [commas] [periods] and [spaces]

current regex is:
		, Contact_POC: {
				required: true
			  , pattern: /^[a-zA-Z0-9,-.!? ]*$/
			}

Open in new window


throwing an invalid message though when John Doe Test2 is used...anyone have any ideas?
0
[Webinar] Learn How Hackers Steal Your Credentials
LVL 8
[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

I need a regex for an invoice amount field to match N.NN format but allow commas:

i.e.: 5,000.00 would be accepted as well as 5000.00 but not 5 or 50 or .50
0
Here's the code I'm using:

				jQuery.validator.addMethod(
		"money",
			function(value, element) {
				var isValidMoney = /^(\d+|\d{1,3}(,\d{3})*)(\.\d{2})?$/.test(value);
				if(isValidMoney) {
					var testValue = value;
					testValue = testValue.replace(",","",-1);
					if(testValue <= 0){
						isValidMoney = false;
					}
				}
				return this.optional(element) || isValidMoney;
			},
			"Insert"
		);

Open in new window


			}
			, Invoice_Amount: {
				  required: true
				, money: true
				, pattern: /^\d+\.\d{0,2}$/
				, min: .01
			}

Open in new window


Won't catch where I need it to. Anyone see where this would be failing?
0
I need a regex to allow letters, hyphens and spaces
0
Server A - IIS configuration: 5 sites. Rewrite rule configured at the server level in IIS for one of the sites (as opposed to being set at the "sites" level). Rewrite rule is working properly here.

Server B - IIS configuration: 5 sites. Rewrite rule configured at the server level in IIS for one of the sites (as opposed to being set at the "sites" level). Rewrite rule is not working here.

The rewrite rule was copied from verbatim from Server A to Server B. Server B is supposed to be a clone of Server A, but it was built from scratch and then had IIS installed fresh (as opposed to being created via a clone function through the hypervisor).

Rewrite rule settings:

In the "Match URL" section
Requested URL: Matches the Pattern
Using: Regular Expressions
Pattern: (.*)
Ignore case checkbox: Checked

In the "Conditions" section
Logical grouping: Match All
Condition input: {CACHE_URL}
Check if input string: Matched the pattern
Pattern: ^(https?:\/\/)?[\w\.-]*(dataviewer)+
Ignore case checkbox: Checked

In the "Action" section
Action type: Rewrite
Action properties: Rewrite URL: http://localhost:8500/{R:0}
Append query string checkbox: Checked
Stop processing of subsequent rules checkbox: Checked

The way it was explained to me, anything that has the word "dataviewer" should match the pattern and therefore get redirected/rewritten. We have a test.html file in the root of the directory to perform testing. When testing the rule by going to the URL/Host …
0
Hi,

  I have a huge text file which i opened in Notepad++.
I want to find the words starting with SP_ and ending in a space.
Then i would like these words to be all listed into a column.

how can i achieve it?
Please help.
0
I am using the following to accept only 0 or 10 digits, but I need to change it to allow 0, 10 or 13. Can someone assist?

 if(/^(\d{0}|\d{10})$/.test(carCount) == false) {
......

Open in new window

0
regex code ( i use windows 7)  to remove .cn and .com  , thank you

john
mary
site.cn
mario.com
sileson
0
I would like to know how to write a regex which does not allow strings ending with dev, qa, prd, staging and the string should be only lowercase.

for example

abcqa not allowed
xyzdev not allowed
pqr allowed
abcdef - allowed
mnxpkdev - not allowed
lmnopstaging - not allowed
0
Hello,

I have some HTML code that looks like:

<img src="/global/images/icons/tip.gif" height="16" width="41" alt="Tip" border="0" align="left">This is some text.

I need to find any HTML tag that contains "tip.gif" and remove the tag, but nothing before or after the tag.

How might I do this?

Thanks in advance.
0
Industry Leaders: We Want Your Opinion!
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

I am trying to make a regex but i'm not very good at it
I am trying to make a regex which starts with Uppercase V and then next two characters should be UPPERCASE alphabets .

Then remaining characters can either be UPPERCASE or numbers.

Maximum limit of string is 15 characters including V

Minimum 4 characters.

Is this right? V[A-Z][A-Z][A-Z1-9]{1,11}$
0
Hi, I want to extract "Towel bath" from the following example, where the start identifier is the first x and the finish is " L " (space L space)

7339700 5xTowel bath L 31/3-5/4 16.75 20.00 13.96

What is the correct expression?  

Here is a doc with examples, which I will update with the solution:
https://docs.google.com/spreadsheets/d/1BFjqRAhuptQTOSYhtlkYQ2P55wIvdAaaKLOSAEAsG3I

Thanks
0
Ive got an XML file which was written by a program and I cant get anything to read it, as its 12Gb in size I dont want to manually go through line by line trying to correct it. Ive managed to figure out phasing the parts I need, however Im stuck when it comes down to the individual elements.

Ive got a line such as:-
<field name="createdby" value="0fb646e4-5590-e611-80e8-1458d05b422c" lookupentity="systemuser" lookupentityname="User 27" />

And I want to be able to split the line up into an array such as:-
     field name="createdby" 
     value="0fb646e4-5590-e611-80e8-1458d05b422c" 
     lookupentity="systemuser" 
     lookupentityname="User 27"

Open in new window


But as the row sometimes has different elements I wanted someway of doing this, but cant figure it out.

I thought I could load each line into a simpleXML_Load_String and extract the data, but becuase the row isnt closed it complains about it. If I manually fix the field to:-
<field name="createdby" value="0fb646e4-5590-e611-80e8-1458d05b422c" lookupentity="systemuser" lookupentityname="User 27">NO Value</field>
Its happy, but I really dont want to go through a 12Gb file and fix manually each line.

Any ideas?
0
If I was to use the following regex, /\d\d\d\.\d/g, I can get a three digits number with a decimal 555.1, etc., but if I want to specify an input range a user enter, and that these number will always include a decimal, for example the minimum would be 70.3, and the max would be 110.5, how would I go about that.
Thx
0
Hi

I am using Microsoft Access.

I need to parse a string which contains multiple lines.
I would like to use Regex to
1) Change all line feeds to "##!##"
2) Remove all other non printing characters

Thank you for you help.
0
I'm writing a software that converts text to HTML and also  I use the regular expression. I wanna know how to identify paragraph in the body of text?
I wrote a snippet of code for identifying paragraph, for example, in this text, it just identifies "my" word.
To identify a paragraph, I look for text that has double spaces before and after it.
Hi

my name is radamal shera.

        private void btnConvert_Click(object sender, EventArgs e)
        {


            string inputText = txtInput.Text;   


           string pattern = @"(\r\n)([a-zA-Z]+)";

            Match result = Regex.Match(txtInput.Text, pattern);
            if (result.Success)
            {
                Debug.WriteLine("match : {0}", result.Value);
            }
       

        }

Open in new window

0

Regular Expressions

6K

Solutions

7

Articles & Videos

5K

Contributors

A regular expression ("regex") is a sequence of characters that define a search pattern, mainly for use in pattern matching with strings, or string matching, i.e. "find and replace"-like operations. Regular expression processors are found in several search engines, search and replace dialogs of several word processors and text editors, and in the command lines of text processing utilities, such as sed and AWK. Many programming languages provide regular expression capabilities, some built-in, for example Perl, JavaScript, Ruby, AWK, and Tcl, and others via a standard library, for example .NET languages, Java, Python and C++ (since C++11). Most other languages offer regular expressions via a library.