title: Regex to match a JSON encoded String
body: <p>Hi I've been trying to create a Regex in Java to match JSON data that I have converted to a string using json_encode. I've been reading through examples on stackoverflow but I'm not sure do they just relate to pure JSON or strings containing JSON representation. I've tried applying a few but can't get them to work. </p>
  
  <p>Looking here:</p>
  
  <p><a href="https://stackoverflow.com/questions/2583472/regex-to-validate-json">Regex to validate JSON</a></p>
  
  <p>And here:</p>
  
  <p><a href="https://stackoverflow.com/questions/32155133/regex-to-match-a-json-string">Regex to match a JSON String</a></p>
  
  <p>This is the string I am trying to use my Regex to match to:</p>
  
  <pre><code>[{"resourceUri":"file:\/home\/admin\/test-modeling\/apache-tomcat-7.0.70\/temp\/IOS\/filetest-file-files.txt#\/\/@statements.12\/@typeList.0\/@enumLiterals.11","severity":"WARNING","lineNumber":333,"column":9,"offset":7780,"length":24,"message":"Enum name should be less than 20 characters"}]
  </code></pre>
  
  <p>I've tried using this answer and it matches fine when I use regex101 for testing.</p>
  
  <p><a href="https://stackoverflow.com/a/6249375/5476612">https://stackoverflow.com/a/6249375/5476612</a></p>
  
  <p>I'm using this regex from here:</p>
  
  <pre><code>/\A("([^"\\]*|\\["\\bfnrt\/]|\\u[0-9a-f]{4})*"|-?(?=[1-9]|0(?!\d))\d+(\.\d+)?([eE][+-]?\d+)?|true|false|null|\[(?:(?1)(?:,(?1))*)?\s*\]|\{(?:\s*"([^"\\]*|\\["\\bfnrt\/]|\\u[0-9a-f]{4})*"\s*:(?1)(?:,\s*"([^"\\]*|\\["\\bfnrt\/]|\\u[0-9a-f]{4})*"\s*:(?1))*)?\s*\})\Z/is
  </code></pre>
  
  <p>However when I try and use it as a string in Java I get escaped character issues.</p>
  
  <p>Can anyone help me with fixing the regex to work as a String to use in Java or help me create one that will work?</p>
  
  <p><strong>EDIT 1:</strong> Here's the full String I am looking at that I am trying to match the JSON string above against:</p>
  
  <pre><code>../../tool/model/toolingValidationReport.php?fileName=test-testing-types.txt&amp;fileSize=18380&amp;validationReport=[{"resourceUri":"file:\/home\/admin\/test-modeling\/apache-tomcat-7.0.70\/temp\/IOS\/filetest-file-files.txt#\/\/@statements.12\/@typeList.0\/@enumLiterals.11","severity":"WARNING","lineNumber":333,"column":9,"offset":7780,"length":24,"message":"Enum name should be less than 20 characters"}] target=
  </code></pre>
  
  <p><strong>EDIT 2:</strong> Here's the Java I am using to perform the regex check. The <code>href</code> variable contains the String content shown in edit 1.</p>
  
  <pre><code>Pattern validationReportPattern = Pattern.compile(getValidationReportPattern());
  Matcher validationReportMatcher = validationReportPattern.matcher(href);
  
  public String getYangValidationReportPattern(){
     return "(\\[\\{.*\\}])"; 
  }
  
  String validationReport  = validationReportMatcher.group(1);
  </code></pre>