in Education by
Regex has a character for or but what is the character for and? For example, say I have a folder with the following files: list.files(path = 'example') # [1] "abc_clean.csv" "abc_other_clean.csv" "abc_other_raw.csv" # [4] "abc_raw.csv" "abc_something_clean.csv" "abc_something_raw.csv" # [7] "def_clean.csv" "def_other_clean.csv" "def_other_raw.csv" # [10] "def_raw.csv" "def_something_clean.csv" "def_something_raw.csv" And I want to match the files that both have `abc' and 'clean'. None of these work: > list.files(path = 'example', pattern = 'abc') [1] "abc_clean.csv" "abc_other_clean.csv" "abc_other_raw.csv" [4] "abc_raw.csv" "abc_something_clean.csv" "abc_something_raw.csv" > list.files(path = 'example', pattern = 'clean') [1] "abc_clean.csv" "abc_other_clean.csv" "abc_something_clean.csv" [4] "def_clean.csv" "def_other_clean.csv" "def_something_clean.csv" > list.files(path = 'example', pattern = 'abc*clean') character(0) > list.files(path = 'example', pattern = '[abc][clean]') [1] "abc_clean.csv" "abc_other_clean.csv" "abc_other_raw.csv" [4] "abc_raw.csv" "abc_something_clean.csv" "abc_something_raw.csv" [7] "def_clean.csv" "def_other_clean.csv" "def_something_clean.csv" For this example, the result I would like is something like: [1] "abc_clean.csv" "abc_other_clean.csv" "abc_something_clean.csv" And please note that this is not about the specific case of listing files. It's not the first time I've tried to get an and on a regex and got confused. data x <- c("abc_clean.csv", "abc_other_clean.csv", "abc_other_raw.csv", "abc_raw.csv", "abc_something_clean.csv", "abc_something_raw.csv", "def_clean.csv", "def_other_clean.csv", "def_other_raw.csv", "def_raw.csv", "def_something_clean.csv", "def_something_raw.csv") JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Why not just allow any character between? abc.*clean.* If you need expect different order, how about use OR: abc.*clean.*|clean.*abc.* Demo

Related questions

0 votes
    __________ uses regex groups instead of a splitting pattern or position. (a) spread() (b) gather() (c) ... Analysis of R Programming Select the correct answer from above options...
asked Feb 10, 2022 in Education by JackTerrance
0 votes
    If two vectors with different lengths perform some operation, the elements of the shorter vector will be used ... of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    I simply can't figure this out and have been trying for awhile. I need a regex that will parse ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    I simply can't figure this out and have been trying for awhile. I need a regex that will parse ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    I simply can't figure this out and have been trying for awhile. I need a regex that will parse ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    I have seen valid JSON written this way: { "version": 1 , "object": { "one": 1 , "two" ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    In order to calculate confidence intervals and hypothesis tests, it is assumed that the errors are independent and ... R Programming Select the correct answer from above options...
asked Feb 9, 2022 in Education by JackTerrance
0 votes
    To start with the new package in RStudio, double-click the pkgname.Rproj file that _______ (a) Delete() ... of R Programming Select the correct answer from above options...
asked Feb 11, 2022 in Education by JackTerrance
0 votes
    regmatches(number, gregexpr(pattern = “2.?2”,text = number)) Is this an example of non-greedy quantifier? If yes, then why and what would be the equivalent greedy quantifier?...
asked Oct 16, 2020 in Technology by JackTerrance
0 votes
    How to print details in the pattern given in java constructors like this Write a program that would print the ... - WallsStreat ?? Select the correct answer from above options...
asked Dec 19, 2021 in Education by JackTerrance
0 votes
    How to print details in the pattern given in java constructors like this Write a program that would print the ... - WallsStreat ?? Select the correct answer from above options...
asked Dec 18, 2021 in Education by JackTerrance
0 votes
    Write a program in JAVA to print this pattern :- 1 12 123 1234 12345 Select the correct answer from above options...
asked Dec 13, 2021 in Education by JackTerrance
0 votes
    please solve this pattern in java I I C I C. S I. C. S. E Select the correct answer from above options...
asked Dec 10, 2021 in Education by JackTerrance
0 votes
    A memory byte location contains the pattern 00101100. What does this pattern represent when interpreted as a binary ... ASCII code? Select the correct answer from above options...
asked Nov 29, 2021 in Education by JackTerrance
...