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 9 years ago.
Improve this question
I have a string like
1372110902.747405 29245 verbose [paymentserv]: === AUTH: ExternalFundingAnalysisStage was successful (rc:0) ===
i want only
AUTH: ExternalFundingAnalysisStage was successful (rc:0)
using regular expression. please help me to sort out the issue.
Thanks in advance
Using PHP:
$var = "1372110902.747405 29245 verbose [paymentserv]: === AUTH: ExternalFundingAnalysisStage was successful (rc:0) ===";
$var = preg_replace("#.*===([^=]+)===.*#i",$1,$var);
Since you didn't specify which language you are using your regex in, any language is presumably a valid response. So, in Perl, you could use the substitution:
s/.*=== (.*) ===.*/$1/;
or the match:
m/=== (.*) ===/;
After the match, $1 will contain the string you wanted to find.
The .* after the second === in the substitute is unnecessary for the sample line of input, but is symmetric with the .* at the beginning of the regex, and symmetry is pleasing. It protects the substitute command from trailing debris; the match doesn't need the protection.
If it's always going to be along the same lines (beginning with AUTH, ending with (rc:#)):
//JavaScript
var str = "1372110902.747405 29245 verbose [paymentserv]: === AUTH: ExternalFundingAnalysisStage was successful (rc:0) ===";
str = str.slice(str.indexOf("AUTH"), str.lastIndexOf(")")+1);
Or with a regex:
str = str.replace(/^.+={3}\s(.+)\s={3}$/,"$1");
for that you also use java regex for detail follow this Tutorial and in your case you can also use sub-string .
Like:
String str ="1372110902.747405 29245 verbose [paymentserv]: === AUTH: ExternalFundingAnalysisStage was successful (rc:0) ===";
String str1=str.subString(58,106);
Stirng str2=str.replace("(","");
Then you get your required answer
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 5 days ago.
Improve this question
I am trying to validate whether my API header is in PascalCase or not, for this, I am using the following regex:
^([A-Z][a-z]*)(-[A-Z0-9][a-z0-9]*)*$
I have a use case where the API contains some keywords that are not in PascalCase and I have to ignore this while validating the header, for example:
X-CUSAPI-Trace-Id While using the above regex I want to ignore the X-CUSAPI- part and then apply the validation on Trace-Id.
I am trying with the following regex but it is not working.
^(?!.*X-CUSAPI-).([A-Z][a-z]*)(-[A-Z0-9][a-z0-9]*)*$
Adding example of API specification:
{
"in": "header",
"name": "X-CUSAPI-Trace-Id",
"description": "TraceID",
"required": false,
"schema": {
"type": "string"
}
}
Spotlight spectral tool which help to parse the JSON and find the name for me to apply the regex to validate either it is PascalCase or not:
header-should-pascal-case:
message: "Request and Response HTTP Header should be pascal-case, separated by hyphens Example: PascalCase-Header"
description: SHOULD prefer hyphenated-pascal-case for HTTP header fields
severity: error
given: $.paths.*.*.parameters[?(#.in=='header')].name
then:
function: pattern
functionOptions:
match: ^.*?(?:X-CUSAPI-)?((?:[A-Z][a-z]+)+(?:-(?:[A-Z0-9][a-z0-9]+)+))\b
The issue with the regex you are using is that the negative lookahead assertion is not correctly placed. You can modify your regex to achieve the desired result by placing the negative lookahead assertion before the beginning of the string anchor (^), like this:
^(?!.X-CUSAPI-)([A-Z][a-z])(-[A-Z0-9][a-z0-9])$
This will ignore any string that contains "X-CUSAPI-" anywhere in it, and then match the remaining string using the PascalCase validation pattern.
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 3 years ago.
Improve this question
I have a field like that named problem:
java.lang.NullPointerException: null\\n09:56:49.712 pl.com.agora.api.client.rest.invocation.FutureCallbacksSupport {HttpClient#2052321524-scheduler} ERROR : Uri invocation failure callback failed.
And I want to exclude from it exception.
(?<exception>java(.*)Exception\z)
So I will have field exception with value: java.lang.NullPointerException
Can not seem to find end of the line which would work. \z or \Z are not working like I want it to.
Didn't find the answer here as well: https://github.com/stedolan/jq/wiki/Docs-for-Oniguruma-Regular-Expressions-(RE.txt)
It is used in logstash and grok match:
filter {
grok {
match => { "message" => '%{TIME:timestamp} (\[)?(%{DATA:logger})?(\])? \{%{DATA:thread}\} %{LOGLEVEL:level} : (?<problem>(.|\r|\n)*)' }
remove_field => ["message"]
}
grok {
match => { "problem" => '(?<exception>java(.*)Exception\z)' }
}
}
The regex (?<exception>java(.*)Exception\z) will search for the following content:
The word java
Any content, including an empty string (.*)
The word Exception
The end of the input \z
However, there is no word "Exception" at the end of the input (\z). You have additional content between "Exception" and the end of the input. So you have to match this additional input as well. It might be as simple as:
(?<exception>java(.*)Exception).*\z
This will be split up into:
The word java
Any content, including an empty string (.*)
The word Exception
Any content, including an empty string (.*)
The end of the input (\z)
Which capture brackets you need depends on what you want to do.
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 8 years ago.
Improve this question
i have a example link:- https://www.google.co.in/search?q=web+service+urls&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a&channel=sb&gfe_rd=cr&ei=ex5iU-6CLMeW8QezvoCgAg
i need a regex to extact that full url from text string.
thanks!
As Marty says, it all depends on which language you are using.
You could do it in JavaScript, like so:
var myString = "i have a example link:- https://www.google.co.in/search?q=web+service+urls&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a&channel=sb&gfe_rd=cr&ei=ex5iU-6CLMeW8QezvoCgAg i need a regex to extact that full url from text string. thanks!";
var myRegexp = /(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,#?^=%&:\/~+#-]*[\w#?^=%&\/~+#-])?/
var match = myRegexp.exec(myString);
alert(match[0]);
Here's a demo
I got the regex from this thread: JavaScript Regex to match a URL in a field of text
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
With the following input:
#element{ color: #333; }
#element2,
.element3,
.whatever{ background: red; }
.test,
.test2, .test3,
#test111,
.element5555, #fooooooter{ display: none; }
#element8 tr .bacon{ font-size: 10000em; }
How do I use regex to match these:
#element
#element2
#element8
#test111
And not match these:
#333
I tried more variations so far and I can't come up with anything useful.
This is what I tried the latest:
(#).*[{]
But it seems to skip some selectors.
#-?[_a-zA-Z]+[_a-zA-Z0-9-]*(?=[^}]*\{)
It explicitly matches valid characters in CSS selector. Which characters are valid in CSS class names/selectors?
http://regexr.com?36e6v
Don't forget to remove comments and quotation like content: '{}' before applying this regex.
Matching comments and quotations is possible with regex. Remove it using unrolling skill, separately.
(I think unrolling is complicated and inefficient enough to rule the integration out.)
It does match color if {} blocks are nested as are in Sass, less
OK,Check out this one,it exactly matches what you need;
^\#[a-z]+[0-9]* //(Multiline = true)
If you need to capture ID Name,use this;
^\#(?<IDName>[a-z]+[0-9]*) //(Multiline = true)
This regex has a capture group named IDName which gives you name of the ID.
Demo here.
Okay, I think I got it (http://regexr.com?36e5i):
#[^{,;]*(?:[{,\n]) will also match ids followed by other selectors (eg., #element8 tr .bacon)
#[^ {,;]*(?:[ {,\n]) will only match ids only (so you'd get the #element8 part from the example above, but not the rest)
try this /#[^1-9]+/g
var t=" #element ";
var p=t.search(/#[^1-9]+/g);
alert(p);
or /#[^1-9.##$%^&*()!]+/g if want to remove more symbols other then numbers
Upadated based on a comment
This will work for you:
/(?![^{]+})(#\S+)\b/g
Check it here: http://regex101.com/r/rF9iR9
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
The Hostname Regex
I'm trying to use pcrepp (PCRE) to extract hostname from url.
the pcre regular expression is as same as Perl 5 regular expression.
for example:
url = "http://www.pandora.com/#/volume/73";
// the match will be "http://www.pandora.com/".
I can't find the correct syntax of the regex for this example.
Needs to work for any url: amazon.com/sds/ should return: amazon.com.
or abebooks.co.uk/isbn="62345627457245"/blabla/ should return abebooks.co.uk
I don't need to check if the url is valid. just to get the hostname.
Something like this:
^(?:[a-z]+://)?[^/]+/?
See Regexp::Common::URI::http which uses sub-patterns defined in Regexp::Common::URI::RFC2396. Examining the source code of those modules should give you a good idea how to put together a decent pattern.
Here is one possibility:
^[a-zA-Z0-9\-\.]+\.(com|org|net|mil|edu|COM|ORG|NET|MIL|EDU)$
And another:
^http\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?$
These and other URL related regular expressions can be found here: Regular Expression Library
string regex1, regex2, finalRegex;
regex1 = "^((\\w+):\\/\\/\\/?)?((\\w+):?(\\w+)?#)?([^\\/\\?:]+):?(\\d+)?(\\/?[^\\?#;\\|]+)?([;\\|])?([^\\?#]+)?\\??";
regex2 = "([^#]+)?#?(\\w*)";
//concatenation
finalRegex= regex1+regex2;
the result will be at the sixth place.
answered in another question I asked: Details.