No internet connection
  1. Home
  2. How to

filter using regular expression with variable in the pattern

By samuel henriques @samuel_henriques
    2020-12-02 22:38:48.817Z

    Hello everyone,
    I apologise for the burden of this question, as I understand Regular Expressions are some "Knights who say Ni!" serving you at the local tax office (or asking for a beer at the bar, I guess) .

    I'm looking for a match from an array

    var a = aafList.split("/").slice(-1).join("/").split(".").shift()

    a = BBC HD audio sync test - this is what I'm looking for

    if I do this:
    var getVideoFile = videoFilePath.filter(x => x.match(/(BBC HD audio sync test)\.(mov|mp4|mxf)$/i))

    I get my path.

    How do I replace the "BBC HD audio sync test" in the regular expression with variable a ?
    or aafList.split("/").slice(-1).join("/").split(".").shift(), will be as good.

    Thank you so much!

    Solved in post #2, click to view
    • 2 replies
    1. samuel henriques @samuel_henriques
        2020-12-03 01:00:35.664Z

        Got it!!

        var getVideoFile = videoFilePath.filter(x => x.includes(a))

        Thank you

        ReplySolution
        1. Dustin Harris @Dustin_Harris
            2020-12-03 03:30:24.278Z

            BTW, somewhat related, I found this great site that helps you test your regex!

            https://regex101.com/r/3UOewQ/8