Click here to Skip to main content
15,886,199 members
Home / Discussions / Regular Expressions
   

Regular Expressions

 
GeneralRe: I need help with a complex regex Pin
Member 1274653217-Apr-23 20:50
Member 1274653217-Apr-23 20:50 
GeneralRe: I need help with a complex regex Pin
Richard MacCutchan17-Apr-23 22:04
mveRichard MacCutchan17-Apr-23 22:04 
QuestionWhat is the regular expression for this string? Pin
Member 1595912122-Mar-23 11:29
Member 1595912122-Mar-23 11:29 
AnswerRe: What is the regular expression for this string? Pin
Richard MacCutchan22-Mar-23 23:12
mveRichard MacCutchan22-Mar-23 23:12 
GeneralRe: What is the regular expression for this string? Pin
k505423-Mar-23 3:52
mvek505423-Mar-23 3:52 
GeneralRe: What is the regular expression for this string? Pin
Richard MacCutchan23-Mar-23 3:55
mveRichard MacCutchan23-Mar-23 3:55 
AnswerRe: What is the regular expression for this string? Pin
jschell23-Mar-23 6:24
jschell23-Mar-23 6:24 
AnswerRe: Where to start - need to extract...using regular expression Pin
k505415-Mar-23 10:39
mvek505415-Mar-23 10:39 
First off, have you tried pre-pending TERM=dumb to your command string. That *should* remove all the control chars from the command output e.g.
Terminal
[k5054@localhost ~]$ TERM=vt100 infocmp
#       Reconstructed via infocmp from file: /usr/share/terminfo/v/vt100
vt100|vt100-am|DEC VT100 (w/advanced video),
        am, mc5i, msgr, xenl, xon,
        cols#80, it#8, lines#24, vt#3,
        acsc=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~,
        bel=^G, blink=\E[5m$<2>, bold=\E[1m$<2>,
        clear=\E[H\E[J$<50>, cr=\r, csr=\E[%i%p1%d;%p2%dr,
        cub=\E[%p1%dD, cub1=^H, cud=\E[%p1%dB, cud1=\n,
        cuf=\E[%p1%dC, cuf1=\E[C$<2>,
        cup=\E[%i%p1%d;%p2%dH$<5>, cuu=\E[%p1%dA,
        cuu1=\E[A$<2>, ed=\E[J$<50>, el=\E[K$<3>, el1=\E[1K$<3>,
        enacs=\E(B\E)0, home=\E[H, ht=^I, hts=\EH, ind=\n, ka1=\EOq,
        ka3=\EOs, kb2=\EOr, kbs=^H, kc1=\EOp, kc3=\EOn, kcub1=\EOD,
        kcud1=\EOB, kcuf1=\EOC, kcuu1=\EOA, kent=\EOM, kf0=\EOy,
        kf1=\EOP, kf10=\EOx, kf2=\EOQ, kf3=\EOR, kf4=\EOS, kf5=\EOt,
        kf6=\EOu, kf7=\EOv, kf8=\EOl, kf9=\EOw, lf1=pf1, lf2=pf2,
        lf3=pf3, lf4=pf4, mc0=\E[0i, mc4=\E[4i, mc5=\E[5i, rc=\E8,
        rev=\E[7m$<2>, ri=\EM$<5>, rmacs=^O, rmam=\E[?7l,
        rmkx=\E[?1l\E>, rmso=\E[m$<2>, rmul=\E[m$<2>,
        rs2=\E<\E>\E[?3;4;5l\E[?7;8h\E[r, sc=\E7,
        sgr=\E[0%?%p1%p6%|%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;m%?%p9%t\016%e\017%;$<2>,
        sgr0=\E[m\017$<2>, smacs=^N, smam=\E[?7h, smkx=\E[?1h\E=,
        smso=\E[7m$<2>, smul=\E[4m$<2>, tbc=\E[3g,

[k5054@localhost ~]$ TERM=dumb infocmp
#       Reconstructed via infocmp from file: /usr/share/terminfo/d/dumb
dumb|80-column dumb tty,
        am,
        cols#80,
        bel=^G, cr=\r, cud1=\n, ind=\n,
[k5054@localhost ~]$ 
In general you can set any environment variable this way, so you might do something like
Shell
LD_LIBRARY_PATH=/home/k5054/lib  DEBUG=1 ./foo
Which would add LD_LIBRARY_PATH and DEBUG variables to the environment, but only for the duration of the given command.

But on to your problem. Assuming you've managed to remove your control characters, what it looks like you want to do is to match any line that does not have an option to it. Based on what you have here, you could match on any line that does not contain either a '[' (i.e. a required argumetn) or a '<' (i.e. an optional argument). So the regex for that would be [^<\[]. Note we need to escape the opening square bracket, otherwise its treated as special character, and that means the regex won't compile.
C++
<h1>include <regex></h1>

regex admin_cmds{"^.+[\\[<].+$"}; // note we need two \\ for C++
if ( ! regex_match(text, admin_cmds ) {
    // text does not contain a '<' or a '['
    // do stuff
}
You could probably pull out the actual strings for the command and the options etc if you use subgroupings, (patter), but I'll leave that as an exercise for you and the documentation: [std::regex_match - cppreference.com](https://en.cppreference.com/w/cpp/regex/regex_match)
Keep Calm and Carry On

QuestionRegular expression to return all keys in a Bibtex file Pin
Member 159423565-Mar-23 5:46
Member 159423565-Mar-23 5:46 
AnswerRe: Regular expression to return all keys in a Bibtex file Pin
Richard Deeming5-Mar-23 21:36
mveRichard Deeming5-Mar-23 21:36 
GeneralRe: Regular expression to return all keys in a Bibtex file Pin
Member 159423566-Mar-23 19:48
Member 159423566-Mar-23 19:48 
AnswerRe: Regular expression to return all keys in a Bibtex file Pin
jschell8-Mar-23 6:57
jschell8-Mar-23 6:57 
QuestionRemove all double quotes not directly preceded or directly followed by a semicolon. Pin
Guus20053-Mar-23 3:55
Guus20053-Mar-23 3:55 
AnswerRe: Remove all double quotes not directly preceded or directly followed by a semicolon. Pin
Richard Deeming3-Mar-23 4:05
mveRichard Deeming3-Mar-23 4:05 
GeneralRe: Remove all double quotes not directly preceded or directly followed by a semicolon. Pin
Guus20053-Mar-23 5:19
Guus20053-Mar-23 5:19 
GeneralRe: Remove all double quotes not directly preceded or directly followed by a semicolon. Pin
Richard Deeming5-Mar-23 21:27
mveRichard Deeming5-Mar-23 21:27 
AnswerRe: Remove all double quotes not directly preceded or directly followed by a semicolon. Pin
jschell6-Mar-23 6:45
jschell6-Mar-23 6:45 
Questionregex expression for us addresses Pin
jpcodex15321-Feb-23 14:55
jpcodex15321-Feb-23 14:55 
GeneralRe: regex expression for us addresses Pin
PIEBALDconsult21-Feb-23 15:02
mvePIEBALDconsult21-Feb-23 15:02 
GeneralRe: regex expression for us addresses Pin
jpcodex15321-Feb-23 15:25
jpcodex15321-Feb-23 15:25 
GeneralRe: regex expression for us addresses Pin
PIEBALDconsult21-Feb-23 15:30
mvePIEBALDconsult21-Feb-23 15:30 
GeneralRe: regex expression for us addresses Pin
Kenneth Haugland21-Feb-23 18:36
mvaKenneth Haugland21-Feb-23 18:36 
AnswerRe: regex expression for us addresses Pin
jschell22-Feb-23 6:06
jschell22-Feb-23 6:06 
GeneralRe: regex expression for us addresses Pin
trønderen22-Feb-23 12:04
trønderen22-Feb-23 12:04 
GeneralRe: regex expression for us addresses Pin
jschell23-Feb-23 6:09
jschell23-Feb-23 6:09 

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.