Does anyone know of a Java dependency or suite of regular expressions that can check a string for instances of code? Preferably one that can check for instances of code based off paramter such a programming language or language type? I would also consider using regular expressions if a comprehensive suite of them existed. My searches are coming up empty although the search terms I'm using aren't very descriptive (don't know exactly how to phrase it).

I can think of some libraries that may work in a way that they werent intended for. However I would assume an entire library would provide a bit more robustness and completeness

  • By code I assume that you mean source code in some, TBD, programming language? Possibly even source code fragments. Jun 28 '17 at 15:23
  • Yes basically I have a script that consumes a web service about 100 times a day (it runs as a cron job). The response is raw text data and my application treats it as any other String data. I would like to parse that data for examples of code fragments. I don't need to identify and separate the code from the other textual data. All I need to do is alert true/false if the service call responds with code and/or code fragments. I dont necessarily need to identify programming language or anytrhing like that. Just need to alert pretty reliably when there is code Jun 28 '17 at 15:32
  • I doubt you will find an answer to query this broad. You want to discover when any string contains a programming langauge text for arbitrary languages? You'd need parsers for virtually every language on the planet, and I can invent one based on any arbitary text you provide. Unless you limit the languages you are williing to check for, you won't find an answer. Revise this or I will downvote it.
    – Ira Baxter
    Jul 3 '17 at 4:13
  • I am looking for a decent regex or library that uses syntax to identify indications of code. Basically I am looking for something similar to the mechanism used by Stack Overflow to alert the user when they are submitting code without using the appropriate markdown. It isn't mission critical and it is only going to be used as a prerequisites for human review. With that said I am not going to specify languages in the original post as it would substantially change the question. If you wish to down vote the question that is within your rights to do so. Jul 3 '17 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.