Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I'm a beginner in regex and trying to create regular expression (doing tests using c++/boost::regex_token_iterator) to find particular pattern:
(* some *)(* interesting *) (*test *) (* regular*)(* expressions *) (* and *)
I want to find words, which much exactly to (* xxxx *) pattern, for single case i'm using below expression:
\(\* .+ \*\)
but cannot figure out how to apply it to string similar to above example. I want to get as result:
(* some *)
(* interesting *)
(* expressions *)
Following fragments should not be taken:
(*test *)
(* regular*)
(* and *)
Any help is highly welcomed.
The simplest one:
\(\*\s\w+\s\*\)
You can use
\(\* [^\s()](?:[^()]*[^\s()])? \*\)
See the regex demo
Details
\(\* - a (* string
[^\s()] - any char other than whitespace, ( and )
(?:[^()]*[^\s()])? - an optional occurrence of any zero or more chars other than ( and ) and then any char other than whitespace, ( and )
\*\) - a *) string
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I using Regex to extract a pattern which is of the form [a-zA-z][0-9]{8} Ex:K12345678
I need to extract this pattern from a string and this pattern should be matched properly
I tried the below but my testcase if failing for this scenario
This is my Regex /[a-zA-Z][0-9]{8}/g
phonne number:9978434276K12345678:My pattern
For this scenario it is failing.
My Sample Code
const expression = /[a-zA-Z][0-9]{8}/;
const content = "phone number:9978434276K12345678:My pattern"
let patternMatch = content.match(expression);
The expected output is K12345678.The Regex which I wrote does not handle this.
You can use String.match(Regex)
"9978434276K12345678".match(/[a-zA-Z][0-9]{8}/)
It returns an array of 4 elements: [String coincidence, index: Number, input: String, groups: undefined]
just stay with the element 0: coincidence and 1: index of the match.
and use this just to check that the string matches at least one
/Regex/.test(String)
/[a-zA-Z][0-9]{8}/.test("9978434276K12345678")
It will return true or false
USE expression without quotation marks
const expression = /[a-zA-Z][0-9]{8}/;
const content = "phone number:9978434276K12345678:My pattern"
let patternMatch = content.match(expression);
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have a comma-separated string and wanted to check if the string has all words irrespective of order using REGEX pattern.
Example: Original String = "help, assist, aid";
Use Cases:
"help, assist, aid" -> return true
"aid, assist, help" -> return true
"aid, help,assist" -> return true
"aid, help" -> return false
"aid, help,support" -> return false
Can someone help me in writing the regex pattern for this use case?
You could use three positive lookahead assertions:
^(?=.*\bhelp\b)(?=.*\baid\b)(?=.*\bassist\b).*$
Each of the three lookaheads is actually zero width, and so would all be evaluated once at the very start of the pattern.
Demo
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have few lines
Eg:
word1-word2-word3-1
word1-word2-word3-23
word1-word2-word3-dr
word1-word2-word3-13-4
word1-word2-word3-drg
word1-word2-word3-word4-4
From the above lines i need the following lines by using Regex
word1-word2-word3-1
word1-word2-word3-23
word1-word2-word3-word4-4
ie. The string ending with a "-{int}"
You can use the pattern -\d+$
The pattern means that we are look for;
-\d+ - hyphen and one or more digits
$ Asserts that we are at the line end.
I don't know what language you are writing this in but assuming you are doing it in Javascript. This pattern can be proved using the code below.
"use strict";
var values = [
"word1-word2-word3-1",
"word1-word2-word3-23",
"word1-word2-word3-dr",
"word1-word2-word3-13-4",
"word1-word2-word3-drg",
"word1-word2-word3-word4-4"
];
values.forEach(value => {
if (/.*-(?!\d+-)\w+-\d+$/.exec(value)) {
console.log(value + " has - integer at the end!");
};
});
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
how can I split or use regex for the results of this msgbox to only get:
"maricruz.tinajero"
I thought about removing all new lines so it's only on one line and then using an index number to get the position of the string I want but im still trying to figure that out.
Try this:(str represents your string above)
Dim obj = str.Substring(str.LastIndexOf("\") + 1)
Forget about using Split or Regex for this:
Dim idx As Integer = msg.LastIndexOf("\"c)
Dim user As String = msg.SubString(idx + 1)
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
sample input text:
a) owner.table_name
b) table_name
can somebody suggest regular expression so that I get out put in such a way that i get text upto "." (if "." exists) and if "." doesnt exist then return empty
output:
a) owner
b) empty
regular expression so that I get out put in such a way that I get text from "." up to end (if "." exists) and if "." doesn't exist then return entire string
output:
a) table_name
b) table_name
The following regex should work:
(?:(\w+)\.)?(\w+)
It creates two capture groups (see this debuggex example to play around with it)
The first group will be empty, with the input table_name. For owner.table_name both groups have the appropriate values.
Here's a regex that would match both in one:
((?<owner>\w+)\.)?(?<table>\w+)
If the tool you are using allows named groups, the first group will be called "owner" and will be any word before a period. The second group will be called "table" and will be any word after a possible "owner".