Click here to Skip to main content
15,438,321 members
Home / Discussions / Regular Expressions
   

Regular Expressions

 
QuestionIs there a way to come up with a regular expression for this? Pin
fame_crane23-Sep-22 4:28
Memberfame_crane23-Sep-22 4:28 
AnswerRe: Is there a way to come up with a regular expression for this? Pin
Gerry Schmitz23-Sep-22 5:56
mveGerry Schmitz23-Sep-22 5:56 
Questionremove parenthese from function like string Pin
Michael Eckstein17-Sep-22 8:56
MemberMichael Eckstein17-Sep-22 8:56 
AnswerRe: remove parenthese from function like string Pin
moxol17-Sep-22 10:43
Membermoxol17-Sep-22 10:43 
GeneralRe: remove parenthese from function like string Pin
Michael Eckstein18-Sep-22 4:55
MemberMichael Eckstein18-Sep-22 4:55 
GeneralRe: remove parenthese from function like string Pin
moxol18-Sep-22 7:28
Membermoxol18-Sep-22 7:28 
GeneralRe: remove parenthese from function like string Pin
Michael Eckstein18-Sep-22 8:01
MemberMichael Eckstein18-Sep-22 8:01 
GeneralRe: remove parenthese from function like string Pin
moxol18-Sep-22 9:19
Membermoxol18-Sep-22 9:19 
GeneralRe: remove parenthese from function like string Pin
Michael Eckstein18-Sep-22 20:22
MemberMichael Eckstein18-Sep-22 20:22 
QuestionRegex to find out length Pin
RanCohen15-Aug-22 23:50
MemberRanCohen15-Aug-22 23:50 
AnswerRe: Regex to find out length Pin
Richard Deeming16-Aug-22 0:14
mveRichard Deeming16-Aug-22 0:14 
AnswerRe: Regex to find out length Pin
Graham Breach16-Aug-22 2:12
MemberGraham Breach16-Aug-22 2:12 
QuestionNon Zero Number Pin
cad-one26-Jul-22 8:11
Membercad-one26-Jul-22 8:11 
AnswerRe: Non Zero Number Pin
k505426-Jul-22 10:46
mvek505426-Jul-22 10:46 
It depends to a certain extent on what "non zero numbers" means, exactly. Does it mean 0 only and exactly, or does it have to not match 0. 0.0 0.00 etc.

For the simple case of a just excluding a zero we can use the following perl regex:
^[-+]?([1-9]\d+|[1-9]+.|\d*.\d+|0?.\d+)$
I've anchored this on line start and end ^ ... $, but you might have other requirements. This will match e.g 1.2 -15 0.03 .12 15. and -0.3, and does not accept any of ., 0, 0., or 1.2.3. However it does accept 0.0, 0.00, etc, and I have not yet found a way to eliminate them from the pattern. There might be a way using lookahead/lookbehind matches Lookahead and Lookbehind Tutorial—Tips &Tricks, but so far I haven't been able to figure out how to tell the regex engine that the lookahead/behind should match the entire pattern. For example we can eliminate 0.0 by adding a negative lookbehind regex of (?<!0.0), but this also elminates 0.03, which is not what is wanted. Maybe someone else knows how to resolve this.

But maybe regex isn't the way to go. If you're working in Java or C# or C++ or ... , it's probably better to just read some input, check that the entire input parses as a number, convert to a number and then omit or complain if the value is zero - depending on what your use case is.
Keep Calm and Carry On

GeneralRe: Non Zero Number Pin
cad-one26-Jul-22 11:09
Membercad-one26-Jul-22 11:09 
QuestionRegex before match Pin
moxol20-Jul-22 22:09
Membermoxol20-Jul-22 22:09 
AnswerRe: Regex before match Pin
Peter_in_278021-Jul-22 1:31
professionalPeter_in_278021-Jul-22 1:31 
GeneralRe: Regex before match Pin
moxol21-Jul-22 2:00
Membermoxol21-Jul-22 2:00 
GeneralRe: Regex before match Pin
jsc4221-Jul-22 2:56
professionaljsc4221-Jul-22 2:56 
GeneralRe: Regex before match Pin
moxol21-Jul-22 3:55
Membermoxol21-Jul-22 3:55 
QuestionPerl regex anchor merely matches at the position of the end of previous match period Pin
marbooth18-Jul-22 6:23
Membermarbooth18-Jul-22 6:23 
AnswerRe: Perl regex anchor merely matches at the position of the end of previous match period Pin
marbooth18-Jul-22 17:18
Membermarbooth18-Jul-22 17:18 
GeneralRe: Perl regex anchor merely matches at the position of the end of previous match period Pin
RedDk20-Jul-22 6:23
MemberRedDk20-Jul-22 6:23 
QuestionIsn't ?= needless? Pin
Member 1570882016-Jul-22 22:38
MemberMember 1570882016-Jul-22 22:38 
AnswerRe: Isn't ?= needless? Pin
Dave Kreskowiak17-Jul-22 6:28
mveDave Kreskowiak17-Jul-22 6:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.