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
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 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 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