I would like to know if it's possible to filter code line from a search with eclipse.
Example: I have to extract all part of code between "" excluding all line starting with 'logger' and also all comment starting with //. I didn't find the exact RegEx to do that...
Can you help me please? Thanks in advance. Best regards.
You can use ^((?:[^\r\n"](?!logger)(?!//))++)("[^"]*+") for that:
the first group (\1) will contain the characters before the first "..." in a line,
the second group (\2) matches "...".
The restriction of this regular expression is that only the first "..." in a line will be matched.
Related
I have been researching this for quite some time but cannot seem to find an answer. Perhaps someone here can help.
I am trying to use sed to replace words in yml / yaml files. Since some of the words are included in the names I want to only replace words that appear after the colon (':').
For example. If the .yml file includes:
en:
label_some_tracker: A tracker
label_all_tracker: All trackers
label_attachment_type_trackers: Select trackers.
tracker_plural: trackers
and I want to replace all occurrences of tracker with issue in all values. The pattern:
s/tracker/issue/
also changes the names of the fields, which breaks my code.
I can reduce the size of the problem somewhat by including terms for all possible variants of a word. For example:
s/trackers/issues/
s/tracker/issue/
but that doesn't deal with all situations.
I have tried inserting a space before the search term:
s/ tracker/ issue/
but that matches names where the search term is at the beginning of the line.
If I search for whole words then it still seems to pick up the names because ':' and '_' are 'non word' characters.
If I try to put spaces at the beginning and end of the search term but then it misses words that are at the end of a line or words patterns with punctuation marks before the training space.
The only sure way seems to be to only replace words after a colon (':') but I cannot seem to figure out how to do that with sed.
Does anyone here know how?
With GNU sed:
sed -E 's/(:.*)tracker/\1issue/g' file
Output:
en:
label_some_tracker: A issue
label_all_tracker: All issues
label_attachment_type_trackers: Select issues.
tracker_plural: issues
Replace second occurance:
sed 's/tracker/issue/2' file
I want to search a file for a specific string and then place a comment at the beginning of that string. But I need an answer that avoids regex, global changes, and all the other fancy stuff.
I wrote this line:
sed -i.bak '/PermitRootLogin no/# PermitRootLogin no/' ./sshd_config
but I get an error:
sed: -e expression #1, char 21: comments don't accept any addresses
I assume the issue is that I need to escape the # character, but I'm not finding any resources on how to do that, or even mentioning it. I've tried various combinations of putting ^ or \ or \^ in front of the # but I'm jut not getting it right.
Please note I am intentionally repeating the text to be replaced. I would like the most simple possible solution to this question: how to replace "XYX" with "# XYZ" in the most obvious possible way.
As indicated in the comments by #mlt , you could try adding an s at the beginning your sed command. Straight from his comment:
s/PermitRootLogin....
I see that you said you're intentionally repeating the test to be replaced. If by that you mean, you want it to be the same, maybe consider grouping your matched text. I understand you may have meant that you just want it hand typed. Anyway, here is how to match the grouped text and add the comment character:
s/(PermitRootLogin)/# \1/
The parens indicated that the matched text should be consider a group, the \1 indicates that you want to put that matched group there.
I hope this was helpful. Happy coding! Leave a comment if you have any questions.
I really need help with coming up with the pattern matching solution...
If the string is <6>[ 84.982642] Killing the process
How can I extract them into three separate strings...
I need one for 6, 84.982642, and Killing the process..
I've tried many things but these brackets and blank spaces are really confusing me and I keep getting the error message
"WARNING: Use of uninitialized value $bracket in pattern match..."
Is there anyway I can somehow write in this way
($num_1, $num_2, $name_process) = split(/[\-,. :;!?()[\]{}]+/);
Not sure how to extract these..
Help Please?
Thank you so much
Assuming the input is in $_
($num_1, $num_2, $name_process) = /^<(\d+)>\[([^\]]+)\]\s+(.*)$/;
This assumes the first token in the angle brackets is always a number. For a little more generality use
($num_1, $num_2, $name_process) = /^<([^>]+)>\[([^\]]+)\]\s+(.*)$/;
Explanation:
<([^>]+)> - a left-angle-bracket followed one or more characters that are not a right angle-bracket, followed by a right-angle bracket.
\[([^\]]+)\] - a left-bracket followed by one or more characters that are not a right bracket, followed by a right bracket
\s+(.*) - one or more spaces, then capture everything starting with the first non-blank after that.
Mainly I want to search for all lines that contain XXX and YYY on the same line in Eclipse.
What would be the correct search expression for that?
This regex should comply with your request:
(XXX.*YYY|YYY.*XXX)
Used under File Search, checking Regular expression.
Use XXX*YYY in file search option.
This will mean that any characters can come in between XXX and YYY.
I'm using regular expression lib icucore via RegKit on the iPhone to
replace a pattern in a large string.
The Pattern i'm looking for looks some thing like this
| hello world (P1)|
I'm matching this pattern with the following regular expression
\|((\w*|.| )+)\((\w\d+)\)\|
This transforms the input string into 3 groups when a match is found, of which group 1(string) and group 3(string in parentheses) are of interest to me.
I'm converting these formated strings into html links so the above would be transformed into
Hello world
My problem is the trailing space in the third group. Which when the link is highlighted and underlined, results with the line extending beyond the printed characters.
While i know i could extract all the matches and process them manually, using the search and replace feature of the icu lib is a much cleaner solution, and i would rather not do that as a result.
Many thanks as always
Would the following work as an alternate regular expression?
\|((\w*|.| )+)\s+\((\w\d+)\)\| Where inserting the extra \s+ pulls the space outside the 1st grouping.
Though, given your example & regex, I'm not sure why you don't just do:
\|(.+)\s+\((\w\d+)\)\|
Which will have the same effect. However, both your original regex and my simpler one would both fail, however on:
| hello world (P1)| and on the same line | howdy world (P1)|
where it would roll it up into 1 match.
\|\s*([\w ,.-]+)\s+\((\w\d+)\)\|
will put the trailing space(s) outside the capturing group. This will of course only work if there always is a space. Can you guarantee that?
If not, use
\|\s*([\w ,.-]+(?<!\s))\s*\((\w\d+)\)\|
This uses a lookbehind assertion to make sure the capturing group ends in a non-space character.