Delete All number or letters - command

I got lines like this.
Matt:karolina1
Datt:hdahdahgda
Patt:leonleon1
Ratt:153513513
I would like delete everything if after ":" are only numbers or letters
So after this good results should looks :
Patt:leonleon1
Matt:karolina1
I had command on notepad++ and works very well but i dont know why on emeditor doesnt.
.*:([[:alpha:]]+|[[:digit:]]+|[##$%^*!#]+)\R
Could somebody help me?

\R should be replaced with $ in EmEditor. Some literals in [] should be escaped by a backslash, and a duplicate # can be removed. Please use .*:([[:alpha:]]+|[[:digit:]]+|[##\$%\^\*\!]+)$ instead.

Related

Replace words but only after a colon

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

Save UITextView String With \n Instead of Line Breaks (Swift)

I have a UITextView in my Swift app in which users can input text. They can input text with as many line breaks as they like but I need to save the string with the newline command (\n). How would I do this?
For example, my user inputs
Line 1
Line 2
Line 3
in the UITextView. If I was to retrieve the string...
let string = textview.text!
this would return
"Line 1
Line 2
Line 3"
when I would like for it to return
"Line1\nLine2\nLine3"
How would I go about doing this? Can I use a form of replacingOccurrences(of:with:)? I feel like I'm missing a fairly obvious solution...
Eureka! After WAY too much research and learning all about String escapes, I found a very simple solution. I'm quite surprised that this isn't an answer out there already (as far as I can tell haha) so hopefully, this helps someone!
It's actually quite simple and this will work of any String you could be using.
textView.text!.replacingOccurrences(of: "\n", with: "\\n")
Explanation:
Ok so as you can tell, it's quite simple. We want to replace the newline command \n with the string "\n". The problem is that if we replace \n with \n, it's just going to transfer over to a newline, not a string. This is why escapes are so important. As you can see, I am replacing \n with \\n. By adding an extra \ we escape the command \n entirely which turns it into a string.
I hope this helps someone! Have a great day!
Have you tried replacing \r with \n? or even \r\n with \n?
I hope I am not making an obvious assumption you considered, but maybe this may come in handy:
Is a new line = \n OR \r\n?

Find the good regex in eclipse

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.

Searching in eclipse using Regular expression

I'm trying to search for occurrences of something in my workspace which consist s of a string, a newline character and a string again
For example :
INSERT( a newline here
Trev
P.S. : Trev is in the next line
I tried using File search in eclipse with Search with Regular expression ticked on
I tried INSERT( \r \n Trev
But seems this isn't coz working as I'm not getting any result. Hope I'm clear with my question. Could anyone please help
You want this regex:
INSERT\(\s+\n\s+Trev
Note that you should escape the ( character as it has a special meaning in regexes.

Perl Pattern Matching extracting inside brackets

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.