want to extract the words which are start with # in notepad++ [closed] - regex

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 12 hours ago.
The community is reviewing whether to reopen this question as of 9 hours ago.
Improve this question
I want to extract the words in given string which are start with '#' in notepad++. Can any one provide your suggestions/solutions?
Here is the string:
#Data is a convenient shortcut annotation that bundles the features of #ToString, #EqualsAndHashCode, #Getter / #Setter and #RequiredArgsConstructor together: In other words

Using Notepad++:
Refer to this answer: Regular expressions in notepad++ (Search and Replace). Open up "Find and Replace" menu. Set search mode to "Regular expression". Then search for your regular expression #\w+ in the "Find what" field.
Another option is to use Python:
Try the re Python module to extract the words from the variable using the same regular expression pattern. The regular expression pattern #\w+ matches any word starting with # followed by one or more word characters.
import re
string = "#Data is a convenient shortcut annotation that bundles the features of #ToString, #EqualsAndHashCode, #Getter / #Setter and #RequiredArgsConstructor together: In other words"
matches = re.findall(r'#\w+', string)
print(matches)
Outputs:
['#Data', '#ToString', '#EqualsAndHashCode', '#Getter', '#Setter', '#RequiredArgsConstructor']

Related

Regular expression Regex to extract a string [closed]

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 4 years ago.
Improve this question
Please can somebody help me, I`m new to regex and have no idea how to do this!.
I`m trying to extract from a list which looks like this...
Joe-Age23-46737-251.aspx
Tim-Age18-46909-451.aspx
Roger-Age41-59768-251.aspx
What I want is this...
46737-251.aspx
46909-451.aspx
59768-251.aspx
so basically anything after the second to last hyphen.
Cheers
Let's translate "everything after the second-to-last hyphen" into regex:
(?<=-)[^-]*-[^-]*$
Explanation:
(?<=-) # Assert starting position right after a hyphen
[^-]* # Match zero or more characters except hyphens
- # Match a single hyphen
[^-]* # see above
$ # until end of string.
Test it live on regex101.com.
Step1 : Split the string on the basis of hyphen(-) . You will get array of strings.
Step2 : extract the second , fifth and eighth
and so on( incremented by 3 ).
Step3 : concatinate all the strings formed in step2.

Groovy regex find and replace [closed]

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 a groovy value like the following:
"hostname blah blah blah"
When that occurs, I want to keep the hostname, but delete everything after it including the first space.
I'm having difficulty with the regex. Any ideas?
Thanks!
To extract the hostname and/or a part of a string by a regular expression can be done in a straightforward way.
If the values are separated by whitespace then can just split the string by a space character and use the first part. Split() method takes in a regular expression as its first argument.
String s = "hostname blah blah blah"
String[] parts = s.split(' ', 2)
if (parts) {
println parts[0]
s = parts[0] // if want to replace the variale s with just the hostname
}
Here is an alternate example using a regular expression to pull out the hostname part of the string value. The first part of the regular expression (\S+) is looking for a sequence of non-whitespace characters. For a set of possible hostnames, a stricter expression could be something like (\w+(\.\w+)*).
import java.util.regex.Matcher
if (s =~ /^(\S+)\s/) {
println Matcher.lastMatcher.group(1)
}

Regex to match custom markdown syntax [closed]

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 want to match the following with multiple capture groups:
Definition 1
: This is the definition text that described the term. Can have markdown formatting and
multiple lines.
Definition 2
: This is the definition text with **markdown**.`code`
I also want to replace it with the following text (HTML definition list):
<dl>
<dt>Definition 1</dt>
<dd>This is the definition text that described the term. Can have markdown formatting and
multiple lines.</dd>
<dt>Definition 1</dt>
<dd>This is the definition text with **markdown**.`code`</dd>
</dl>
You could do this in two steps:
1. Insert the dt and dd tags
Perform a search with:
(.*)\R: ((?:.+(?:\R|$))*?)(?=\R|.*\R:|$)/g
and substitute by:
<dt>$1</dt>\n<dd>$2</dd>\n
See regex tester.
2. Add the dl tags
Use the result of the previous substitution and perform the following search:
/(<dt>.*?<\/dd>(?!\s*<dt>))/gs
and substitute by:
<dl>\n$1\n</dl>
See regex tester.
Remarks
If the \R escape is not supported, use \n instead.
The back-references $1, $2 might need to be changed to \1, \2 depending on your regex engine.

Regex: Matching only groups that have a specific word embedded [closed]

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 cannot figure out how to match only on groups that contain a certain word ('test' for example below). It is a big text file and the groups start with a line 'Group x' and include text with an empty line separation to the next group. I think I need to use lookaheads and lookbehinds but don't know how. I can use vb.net for this but trying to test out different expressions in the regex testers and can't get anywhere.
Group 1
adfdf
dd test ddfdf
dfdfadf
Group 2
ddfadfa
Group 3
add test
adfdff
Group 4
adfdf
Expected 2 matches:
Group 1
adfdf
dd test ddfdf
dfdfadf
Group 3
add test
adfdff
Start your pattern with ^Group \d+$ and end with (?:^$|\Z). In the middle match test but not preceeded by an empty line $(?:.(?!^$) (see Regular expression to match a line that doesn't contain a word? for details on how the latter works). Don't forget the m and s modifiers:
^Group \d+$(?:.(?!^$))*?test.*?(?:^$|\Z)
Demo: https://regex101.com/r/kM9qB3/2

Perl Regex Ban Log [closed]

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
I want to be able to match all of the following strings to my regex below. It doesnt seem to be working. Any suggestions?
Strings to compare :
5878ce43aa3f1e1d713427d118115310 -1 Script Kiddie <perm>
f939f88b50fa5f0099b6751e7be27761 -1 Hacking <perm>
468f6634c5a9b00b5b3872dd6437143f 1356474103 Being Annoying <7day>
This is my perl code. It isnt working at the moment. Any suggestions?
my $bn_re = q{(.+?) (\d+) (.+?)};
If the first two fields are always without whitespace in them, you can use split to great effect, using the LIMIT option to only get three fields:
my ($str, $num, $other) = split ' ', $_, 3;
That is, assuming you read the file something like this:
while (<>) {
... # your code here
}
Also, this:
my $bn_re = q{(.+?) (\d+) (.+?)};
is not a regex. You may be confusing q() with qr(). You may also be confusing the functionality of
$str =~ $bn_re;
Which will automagically include the regex in a match operator m//. But you should use qr(). The q() operator does what the single quote does.
Also, you should be aware that .+? will match a single char if you allow it. As it does at the end of your "regex". At the end of your string, either do
... (.+)/ # matching greedily
... (.+?)$/ # using anchor to end of string
$bn_re =~ /[0-9a-z]+?\s[-0-9]+\s[\w\s]+?[<>a-z0-9]+?/i