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
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 log in below format ,
15:58:45,999 INFO [name] [place] [id1] [id2] [my_name,my_id,address,null,street,country,pincode] verified. Allowing access
I have to identify the word with , inside a [] and print the 4th word in it. here in example "null" is the value
I have tried [a-zA-Z],[a-zA-Z0-9_] regex. It gives me all of the below matches. Could you please help me to get only "null" value from here. Don't know where I'm missing the logic
my_name
my_id
address
null
street
country
pincode
[a-zA-Z],[a-zA-Z0-9_]
You can use something like this:
\[(?:\w+,){3}(\w+)(?:,\w+)*?]
..which will capture the 4th word in the first capturing group.
Demo.
Note that \w matches everything that is matched by [a-zA-Z0-9_].
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 5 years ago.
Improve this question
How would I remove all HTML tags while the string is a 'std::string'.
Input: <b>Blah blah blah</b>
Expected output after HTML tags stripped should be: Blah blah blah
Use std::string::find() to search for < and > then use std::string::replace to replace them and the content within with an empty string "".
Repeat this in a loop until find() returns std::npos, which indicates that the searched character couldn't be found.
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
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 1 year ago.
Improve this question
I'm not familiar with the regex string,
Let say i have this line of data in a file.:
define('DB_USER', 'audrey');
define('DB_USER', 'bobby');
define('DB_USER', 'cindy');
define('DB_USER', 'donny');
...
and i need to replace it into this:
define('DB_USER', 'admin');
define('DB_USER', 'admin');
define('DB_USER', 'admin');
define('DB_USER', 'admin');
...
Basically changing all the DB_user to admin. How can i do this with Notepad++ Find&Replace function. Thanks
Search for
define\('DB_USER',\s*'[^']*'\);
and replace with
define('DB_USER', 'admin');
If the text is formatted as above, I'd use "block select"
Place cursor on ' in 'audrey and hold down left-alt-key and select the column, then just type in the replacement-wrord.
Try this
Search what: ,\s'\K\w+
Replace with: admin