Regex to search through a file for a set of parentheses with eight characters inside them, all 1s or 0s, with...












3















I'm trying to search through a file for a set of parentheses with eight characters inside them, all 1s or 0s, with at least one 1.
I currently am using the regex below, enumerating all possible such parentheses sets, i.e. brute forcing it.
Is there a better way to do this?



My regex:



(11111110)|(11111101)|(11111100)|(11111011)|(11111010)|(11111001)|(11111000)|...|(11111111) etc.










share|improve this question

























  • Yeah, use grep -oP 'b(?=[01]{8}b)0*1[10]*'

    – Wiktor Stribiżew
    Nov 13 '18 at 19:10











  • See my answer below, I modified my comment as I did not realize you wanted to match these binary data inside parentheses.

    – Wiktor Stribiżew
    Nov 13 '18 at 19:34
















3















I'm trying to search through a file for a set of parentheses with eight characters inside them, all 1s or 0s, with at least one 1.
I currently am using the regex below, enumerating all possible such parentheses sets, i.e. brute forcing it.
Is there a better way to do this?



My regex:



(11111110)|(11111101)|(11111100)|(11111011)|(11111010)|(11111001)|(11111000)|...|(11111111) etc.










share|improve this question

























  • Yeah, use grep -oP 'b(?=[01]{8}b)0*1[10]*'

    – Wiktor Stribiżew
    Nov 13 '18 at 19:10











  • See my answer below, I modified my comment as I did not realize you wanted to match these binary data inside parentheses.

    – Wiktor Stribiżew
    Nov 13 '18 at 19:34














3












3








3








I'm trying to search through a file for a set of parentheses with eight characters inside them, all 1s or 0s, with at least one 1.
I currently am using the regex below, enumerating all possible such parentheses sets, i.e. brute forcing it.
Is there a better way to do this?



My regex:



(11111110)|(11111101)|(11111100)|(11111011)|(11111010)|(11111001)|(11111000)|...|(11111111) etc.










share|improve this question
















I'm trying to search through a file for a set of parentheses with eight characters inside them, all 1s or 0s, with at least one 1.
I currently am using the regex below, enumerating all possible such parentheses sets, i.e. brute forcing it.
Is there a better way to do this?



My regex:



(11111110)|(11111101)|(11111100)|(11111011)|(11111010)|(11111001)|(11111000)|...|(11111111) etc.







regex






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 21:15









ttarchala

2,1071929




2,1071929










asked Nov 13 '18 at 19:04









anonanon

183




183













  • Yeah, use grep -oP 'b(?=[01]{8}b)0*1[10]*'

    – Wiktor Stribiżew
    Nov 13 '18 at 19:10











  • See my answer below, I modified my comment as I did not realize you wanted to match these binary data inside parentheses.

    – Wiktor Stribiżew
    Nov 13 '18 at 19:34



















  • Yeah, use grep -oP 'b(?=[01]{8}b)0*1[10]*'

    – Wiktor Stribiżew
    Nov 13 '18 at 19:10











  • See my answer below, I modified my comment as I did not realize you wanted to match these binary data inside parentheses.

    – Wiktor Stribiżew
    Nov 13 '18 at 19:34

















Yeah, use grep -oP 'b(?=[01]{8}b)0*1[10]*'

– Wiktor Stribiżew
Nov 13 '18 at 19:10





Yeah, use grep -oP 'b(?=[01]{8}b)0*1[10]*'

– Wiktor Stribiżew
Nov 13 '18 at 19:10













See my answer below, I modified my comment as I did not realize you wanted to match these binary data inside parentheses.

– Wiktor Stribiżew
Nov 13 '18 at 19:34





See my answer below, I modified my comment as I did not realize you wanted to match these binary data inside parentheses.

– Wiktor Stribiżew
Nov 13 '18 at 19:34












3 Answers
3






active

oldest

votes


















3














Use



grep -oP '((?=[01]{8}))0*1[10]*)' file


See the regex demo.



Details





  • -o - outputs matches rather than matching lines


  • P - enables PCRE regex engine


Pattern





  • ( - a ( char


  • (?=[01]{8})) - a positive lookahead that requires eight 0 or 1 chars up to to a )


  • 0* - 0+ zeros


  • 1 - a 1 char


  • [10]* - 0 or more zeros or ones


  • ) - a ).






share|improve this answer





















  • 1





    This works great too. Of course, as it is by Wiktor "The Great Regexer" :)

    – Pushpesh Kumar Rajwanshi
    Nov 13 '18 at 19:37



















1














You may use this regex,



((?=[10]{8})(?=.*1.*).{8})


Explanation:





  • ( --> Matches a literal ( (starting brace)


  • (?=[10]{8}) --> Look ahead ensuring next eight characters are composed of zero and one only


  • (?=.*1.*) --> Look ahead ensuring the presence of at least one '1' character


  • .{8} --> matches exactly eight characters


  • ) --> Matches a literal ) (closing brace)


Demo






share|improve this answer
























  • Thanks for your help, however that still finds the string (00000000) which I was hoping to avoid, as its the base case

    – anon
    Nov 13 '18 at 19:31











  • It doesn't match (00000000). Check this regex101.com/r/lr8haq/2

    – Pushpesh Kumar Rajwanshi
    Nov 13 '18 at 19:32



















0














This regex could also work:



(?!(00000000))(d{8})





share|improve this answer


























  • See Lookarounds (Usually) Want to be Anchored.

    – Wiktor Stribiżew
    Nov 13 '18 at 21:24











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53287890%2fregex-to-search-through-a-file-for-a-set-of-parentheses-with-eight-characters-in%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














Use



grep -oP '((?=[01]{8}))0*1[10]*)' file


See the regex demo.



Details





  • -o - outputs matches rather than matching lines


  • P - enables PCRE regex engine


Pattern





  • ( - a ( char


  • (?=[01]{8})) - a positive lookahead that requires eight 0 or 1 chars up to to a )


  • 0* - 0+ zeros


  • 1 - a 1 char


  • [10]* - 0 or more zeros or ones


  • ) - a ).






share|improve this answer





















  • 1





    This works great too. Of course, as it is by Wiktor "The Great Regexer" :)

    – Pushpesh Kumar Rajwanshi
    Nov 13 '18 at 19:37
















3














Use



grep -oP '((?=[01]{8}))0*1[10]*)' file


See the regex demo.



Details





  • -o - outputs matches rather than matching lines


  • P - enables PCRE regex engine


Pattern





  • ( - a ( char


  • (?=[01]{8})) - a positive lookahead that requires eight 0 or 1 chars up to to a )


  • 0* - 0+ zeros


  • 1 - a 1 char


  • [10]* - 0 or more zeros or ones


  • ) - a ).






share|improve this answer





















  • 1





    This works great too. Of course, as it is by Wiktor "The Great Regexer" :)

    – Pushpesh Kumar Rajwanshi
    Nov 13 '18 at 19:37














3












3








3







Use



grep -oP '((?=[01]{8}))0*1[10]*)' file


See the regex demo.



Details





  • -o - outputs matches rather than matching lines


  • P - enables PCRE regex engine


Pattern





  • ( - a ( char


  • (?=[01]{8})) - a positive lookahead that requires eight 0 or 1 chars up to to a )


  • 0* - 0+ zeros


  • 1 - a 1 char


  • [10]* - 0 or more zeros or ones


  • ) - a ).






share|improve this answer















Use



grep -oP '((?=[01]{8}))0*1[10]*)' file


See the regex demo.



Details





  • -o - outputs matches rather than matching lines


  • P - enables PCRE regex engine


Pattern





  • ( - a ( char


  • (?=[01]{8})) - a positive lookahead that requires eight 0 or 1 chars up to to a )


  • 0* - 0+ zeros


  • 1 - a 1 char


  • [10]* - 0 or more zeros or ones


  • ) - a ).







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 13 '18 at 19:36

























answered Nov 13 '18 at 19:30









Wiktor StribiżewWiktor Stribiżew

314k16133212




314k16133212








  • 1





    This works great too. Of course, as it is by Wiktor "The Great Regexer" :)

    – Pushpesh Kumar Rajwanshi
    Nov 13 '18 at 19:37














  • 1





    This works great too. Of course, as it is by Wiktor "The Great Regexer" :)

    – Pushpesh Kumar Rajwanshi
    Nov 13 '18 at 19:37








1




1





This works great too. Of course, as it is by Wiktor "The Great Regexer" :)

– Pushpesh Kumar Rajwanshi
Nov 13 '18 at 19:37





This works great too. Of course, as it is by Wiktor "The Great Regexer" :)

– Pushpesh Kumar Rajwanshi
Nov 13 '18 at 19:37













1














You may use this regex,



((?=[10]{8})(?=.*1.*).{8})


Explanation:





  • ( --> Matches a literal ( (starting brace)


  • (?=[10]{8}) --> Look ahead ensuring next eight characters are composed of zero and one only


  • (?=.*1.*) --> Look ahead ensuring the presence of at least one '1' character


  • .{8} --> matches exactly eight characters


  • ) --> Matches a literal ) (closing brace)


Demo






share|improve this answer
























  • Thanks for your help, however that still finds the string (00000000) which I was hoping to avoid, as its the base case

    – anon
    Nov 13 '18 at 19:31











  • It doesn't match (00000000). Check this regex101.com/r/lr8haq/2

    – Pushpesh Kumar Rajwanshi
    Nov 13 '18 at 19:32
















1














You may use this regex,



((?=[10]{8})(?=.*1.*).{8})


Explanation:





  • ( --> Matches a literal ( (starting brace)


  • (?=[10]{8}) --> Look ahead ensuring next eight characters are composed of zero and one only


  • (?=.*1.*) --> Look ahead ensuring the presence of at least one '1' character


  • .{8} --> matches exactly eight characters


  • ) --> Matches a literal ) (closing brace)


Demo






share|improve this answer
























  • Thanks for your help, however that still finds the string (00000000) which I was hoping to avoid, as its the base case

    – anon
    Nov 13 '18 at 19:31











  • It doesn't match (00000000). Check this regex101.com/r/lr8haq/2

    – Pushpesh Kumar Rajwanshi
    Nov 13 '18 at 19:32














1












1








1







You may use this regex,



((?=[10]{8})(?=.*1.*).{8})


Explanation:





  • ( --> Matches a literal ( (starting brace)


  • (?=[10]{8}) --> Look ahead ensuring next eight characters are composed of zero and one only


  • (?=.*1.*) --> Look ahead ensuring the presence of at least one '1' character


  • .{8} --> matches exactly eight characters


  • ) --> Matches a literal ) (closing brace)


Demo






share|improve this answer













You may use this regex,



((?=[10]{8})(?=.*1.*).{8})


Explanation:





  • ( --> Matches a literal ( (starting brace)


  • (?=[10]{8}) --> Look ahead ensuring next eight characters are composed of zero and one only


  • (?=.*1.*) --> Look ahead ensuring the presence of at least one '1' character


  • .{8} --> matches exactly eight characters


  • ) --> Matches a literal ) (closing brace)


Demo







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 '18 at 19:28









Pushpesh Kumar RajwanshiPushpesh Kumar Rajwanshi

7,5282927




7,5282927













  • Thanks for your help, however that still finds the string (00000000) which I was hoping to avoid, as its the base case

    – anon
    Nov 13 '18 at 19:31











  • It doesn't match (00000000). Check this regex101.com/r/lr8haq/2

    – Pushpesh Kumar Rajwanshi
    Nov 13 '18 at 19:32



















  • Thanks for your help, however that still finds the string (00000000) which I was hoping to avoid, as its the base case

    – anon
    Nov 13 '18 at 19:31











  • It doesn't match (00000000). Check this regex101.com/r/lr8haq/2

    – Pushpesh Kumar Rajwanshi
    Nov 13 '18 at 19:32

















Thanks for your help, however that still finds the string (00000000) which I was hoping to avoid, as its the base case

– anon
Nov 13 '18 at 19:31





Thanks for your help, however that still finds the string (00000000) which I was hoping to avoid, as its the base case

– anon
Nov 13 '18 at 19:31













It doesn't match (00000000). Check this regex101.com/r/lr8haq/2

– Pushpesh Kumar Rajwanshi
Nov 13 '18 at 19:32





It doesn't match (00000000). Check this regex101.com/r/lr8haq/2

– Pushpesh Kumar Rajwanshi
Nov 13 '18 at 19:32











0














This regex could also work:



(?!(00000000))(d{8})





share|improve this answer


























  • See Lookarounds (Usually) Want to be Anchored.

    – Wiktor Stribiżew
    Nov 13 '18 at 21:24
















0














This regex could also work:



(?!(00000000))(d{8})





share|improve this answer


























  • See Lookarounds (Usually) Want to be Anchored.

    – Wiktor Stribiżew
    Nov 13 '18 at 21:24














0












0








0







This regex could also work:



(?!(00000000))(d{8})





share|improve this answer















This regex could also work:



(?!(00000000))(d{8})






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 13 '18 at 20:18









Tiago Martins Peres

2,21341935




2,21341935










answered Nov 13 '18 at 20:11









ecaglecagl

1




1













  • See Lookarounds (Usually) Want to be Anchored.

    – Wiktor Stribiżew
    Nov 13 '18 at 21:24



















  • See Lookarounds (Usually) Want to be Anchored.

    – Wiktor Stribiżew
    Nov 13 '18 at 21:24

















See Lookarounds (Usually) Want to be Anchored.

– Wiktor Stribiżew
Nov 13 '18 at 21:24





See Lookarounds (Usually) Want to be Anchored.

– Wiktor Stribiżew
Nov 13 '18 at 21:24


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53287890%2fregex-to-search-through-a-file-for-a-set-of-parentheses-with-eight-characters-in%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Full-time equivalent

Bicuculline

さくらももこ