Regular expression in sublime - regex

I have this thing where I usual have something like (but not always)
- 30 30: 0 4 58 E
and that must be
- 30 30
: 0 4 58 E
or, in another case
- 32 32
: 0 2 63 All
must remain as it is
- 32 32
: 0 2 63 All
So any : must always be on the next line.
Is there an regex for fixing every case of this (so that it only does this when the : isn't already on a new line?
I'm using Sublime text as editor

when the ":" is already on a new line, it can't be given another one
Then you want to use a negative lookbehind:
(?<!\n):
Replace that with \n:.
If lookbehind is not supported, you also could match colons that follow digits: Replace (\d): with $1\n: - using a capturing group.

Related

Regular Expression

I'm trying to get the regular expression to work (using jQuery) for a specific pattern I need.
I need following pattern:
First two character
s of the string need to be numbers (0-9) but maximum number is 53. for numbers below 10 a leading 0 is required
Character on position 3 needs to be a .
the next 4 characters need to be a number between 0-9, minimum number should be 2010, maximum 2050
so, Strings like 01.2020, 21.2020, or 45.2020 have to match but 54.2020 or 04.2051 must not.
I tried to write the regex without the min and max requirement first and I'm testing the string using regex101.com but I'm unable to get it to work.
acording to the definition /^[0-9]{2}\.\d[0-9]{4}$/ should allow me to insert the strings in the format NN.NNNN.
thankful for any input.
2 numbers from 00 to 53 can be matched using this : (?:[0-4][0-9]|5[0-3]) (00 -> 49 or 50 -> 53)
Character on position 3 needs to be a . : you've already got the \.
a number between 2010 and 2050 -> 20(?:[1-4][0-9]|50) (20 followed by either 10 -> 49 or 50)
This gives :
(?:[0-4][0-9]|5[0-3])\.20(?:[1-4][0-9]|50)

Regex Validate French mobile number

I'm trying to validate french mobile numbers:
I have already removed all non numeric character and the eventual 00 at beginning, and rules are:
start with 06 or 07 or 09
is 10 digit long:
thus :
/^0(6|7|9)\d{8}$/
but (seems) that if countrycode (33) is present, the leading zero has to be avoided, but at this point I cannot create the right regex, since with number:
33614444444
/^(33|0)?(6|7|9)\d{8}$/
it works, but works also with
614444444
while it should not
can suggest solution?
you can do it using the regex
^(33|0)(6|7|9)\d{8}$
see the regex101 demo
Why don't you simply use /^(33|0)(6|7|9)\d{8}$/ ?
I do not think you need the quantifier ?.
When you add ? after (33|0). It implies either none of them is present or one of 33 or 0 is present. It would match all the following -
614444444 // none present
0614444444 // 0 present
33614444444 // 33 present

Lookaround backtracks right before closing bracket

Note: this question is an outcome from another answer that as of now all its comments are removed.
In case of using a lookaround construct within a RegEx there is a backtrack or a kind of that takes place right before closing bracket. As I'm aware this backtrack comes to output of Perl and PCRE debuggers:
The question is what is this backtrack, why is it there and how is it interpreted as a backtrack?
The backtrack is a lie.
It's just a consequence of how the regex101 debugger is implemented. It uses a PCRE feature (flag) called PCRE_AUTO_CALLOUT. This flag tells the PCRE engine to invoke a user-defined function at every step of matching. This function receives the current match status as input.
The catch is that PCRE doesn't tell the callout when it really backtracks. Regex101 has to infer that from the match status.
As you can see, in the step before the "backtrack" occurs, the current matched text is a_, and just after you get out of the lookahead, it's reverted to a. Regex101 notices the matched text is shorter and therefore it infers that a backtrack must have happened, with the confusing outcome you noticed.
For reference, here's the internal PCRE representation of the pattern with auto-callout enabled:
$ pcretest
PCRE version 8.38 2015-11-23
re> /a(?=_)_b/DC
------------------------------------------------------------------
0 59 Bra
3 Callout 255 0 1
9 a
11 Callout 255 1 5
17 17 Assert
20 Callout 255 4 1
26 _
28 Callout 255 5 0
34 17 Ket
37 Callout 255 6 1
43 _
45 Callout 255 7 1
51 b
53 Callout 255 8 0
59 59 Ket
62 End
------------------------------------------------------------------
Capturing subpattern count = 0
Options:
First char = 'a'
Need char = 'b'
As you can see, there's no branching opcode there, just an Assert.

Edit end of line in Notepad++

I am trying to add characters at the end of every line. Those characters are a comma and a name (same for all the columns) as well as a number (incrementing from 1 to end number). My columns are not regular and I have many lines so I need to find the expression to use in the Find and Replace.
My document looks like this:
1,-16 37 25.3,65 32 36.1
2,-16 18 5.9,66 6 37.9
3,-16 17 54.3,66 6 58.7
4,-15 59 23.3,66 40 9.2
5,-15 59 8.2,66 40 36.3
I need it to look like that:
1,-16 37 25.3,65 32 36.1,ECS1
2,-16 18 5.9,66 6 37.9,ECS2
3,-16 17 54.3,66 6 58.7,ECS3
4,-15 59 23.3,66 40 9.2,ECS4
5,-15 59 8.2,66 40 36.3,ECS5
Does anyone know the appropriate expression?
If you select "Regular expression" in the Replace dialog then you can match the leading character and the remainder using ^(\d)(.*)$ in the "Find what" field and replace it using the captured parts in the "Replace with" field: \1\2,ECS\1 where backslash-digit gets substituted with the captured match from one of the parenthetical match expressions.

How to add zero in front of single digit values using REGEX in pentaho

I have the month values in a flat file like
Month
12
11
1
2
8
10
now i want to add zero in front of single digit values & double digit as same.
output should be like
Month
12
11
01
02
08
10
This am doing in PENTAHO (I will implement in Replace in string step)
I am not aware of PENTAHO. But following regex should work for most of the languages
Match : \b([0-9])\b
Replace : 0$1
regex101 demo