in Education by
I'm trying to formulate how to write one regex to match this: I would like to write a regex to match on words like: backbone,jquery,bootstrap,yui and match on javascript library versions like 0.5.0 or 1.8 (as shown). How can I reasonably do this with python 3? 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
Maybe a starting point: use two expressions, one for the version, one for the lib: import re urls = """https://ajax.cdnjs.com/ajax/libs/backbone.js/0.5.0/backbone-min.js https://ajax.cdnjs.com/ajax/libs/backbone-0.5.0.js https://ajax.cdnjs.com/ajax/libs/jquery-min.js https://ajax.cdnjs.com/ajax/libs/jquery-1.6.3.js https://ajax.cdnjs.com/ajax/libs/backbone.js/0.5.0/backbone-min.js https://stackpath.bootstrapcdn.com/bootstrap/4.0.2/js/jquery.validate.js http://code.jquery.com/mobile/1.0rc2/jquery.mobile-1.0rc2.min.js"> http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js http://yui.yahooapis.com/3.5.0/build/yui/yui-min.js""" rx_version = re.compile(r'[-/](\d+[.\w]*)[/.]') rx_lib = re.compile(r'/([a-z]+)[^/]+$') for url in urls.split("\n"): version, lib = None, None # version m = rx_version.search(url) if m: version = m.group(1) m = rx_lib.search(url) if m: lib = m.group(1) print(lib, version) This yields backbone 0.5.0 backbone 0.5.0 jquery None jquery 1.6.3 backbone 0.5.0 jquery 4.0.2 jquery 1.0rc2 jquery 1.9.2 jquery 1.8 yui 3.5.0

Related questions

0 votes
    I'm trying to formulate how to write one regex to match this: I would like to write a regex to ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 1, 2022 in Education by JackTerrance
0 votes
    I'm trying to formulate how to write one regex to match this: I would like to write a regex to ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    Each time a python file is imported that contains a large quantity of static regular expressions, cpu cycles ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
0 votes
    Each time a python file is imported that contains a large quantity of static regular expressions, cpu cycles ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
0 votes
    Each time a python file is imported that contains a large quantity of static regular expressions, cpu cycles ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 24, 2022 in Education by JackTerrance
0 votes
    I switched from Perl to Python about a year ago and haven't looked back. There is only one idiom ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 21, 2022 in Education by JackTerrance
0 votes
    I switched from Perl to Python about a year ago and haven't looked back. There is only one idiom ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    I have a data which looks like EX:992215:SHOW:CMS016:000335:ESP:15:EUR:Euro:4:14:01/05/2009 :30 ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I have a data which looks like EX:992215:SHOW:CMS016:000335:ESP:15:EUR:Euro:4:14:01/05/2009 :30 ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I have a data which looks like EX:992215:SHOW:CMS016:000335:ESP:15:EUR:Euro:4:14:01/05/2009 :30 ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 3, 2022 in Education by JackTerrance
0 votes
    Deduce the formula of F1 Score? What is the need of its formulation? Select the correct answer from above options...
asked Nov 12, 2021 in Education by JackTerrance
0 votes
    I'm trying to embed python into a C application. For the moment, I am trying to get the following ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    I want to compress some files (into the ZIP format) and encrypt them if possible using C#. Is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    In modern software development, a large portion of code is reused from open source and third-party libraries. False True...
asked Oct 28, 2020 in Technology by JackTerrance
0 votes
    Crashpad is an error reporting system for c++ apps. https://chromium.googlesource.com/crashpad/crashpad/+/ ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
...