Invalid token '\n' found on line 31 at column 0 - coldfusion

I have a CF-7 file with 30 line of code.I am getting an error on the 31st line saying
** Invalid token '\n' found on line 31 at column 0.**
what does the error message mean?
Regards
Vas

The error is slightly misleading. The CF compiler is trying to parse the code but failing because of a unclosed tag / block so it keeps on trying to parse until the end of the document and then it reports the error since the last thing it found was a newline which isn't closing the tag that's currently open. So go over the source code and check where you aren't properly closing something. The error is before line 31.
it could be something like
<cfif foo eq "Bar">
Still haven't found what I'm looking for.
and then not having a closing tag. Or it could also be you have a CF style comment
<!--- but are closing it as a HTML comment -->

There is a new line character at the beginning of the line. Is whatever you are using to parse the file is not expecting an empty line?

Related

Splunk rex expression to remove comma if present in json file

I have stuck in a small issue where I need to remove last character "," ( if present) from JSON log file. I am using it in Splunk.
It seems simple and I was hoping my regex will work but its not working.
My Attempts :
1. s/\(,$\)?//g
2. s/,$//g
3. s/\(.*\),/\1/
FYI: My json file is nested, along with removing last character, I am removing some header and footers from this file and breaking the 1 event in multiple. Due to event break it has , at the end of each event.
For better understanding can refer this link which I posted on Splunk Community fourm
https://community.splunk.com/t5/Getting-Data-In/Updated-Help-in-event-break-for-json-file/td-p/569676
Actually there was an extra space at the end so below one is working but it cause another issue.
Working Regex s/\(,\s$\)//g
because I am using it with other regex and event break. Not event break is not working.
Other Regex
SEDCMD-removefooter = s/(\]\,).*//g
SEDCMD-removeheader = s/\{\"data\": \[//g
LINE_BREAKER = ([\r\n,]*(?:{[^[{]+\[)?){"links"
I resolved the issue
Working regex
SEDCMD-replacequotes = s/'/"/g
SEDCMD-removecomma = s/,\s$//g
SEDCMD-removefooter = s/(\]\,).*//g
SEDCMD-removeheader = s/\{.data.: \[//g

Regex to match invalid CSV line with unescaped quotes

Let's say I have a file of strings like
11,"abc","def"
12,"ab "c"","def" // invalid
13,"ab,"c"","def" // invalid
14,""a" b,c","def" // invalid
15,""a", "b"c","def" // invalid
As you can see some of the double quotes are unescaped. I'd like to filter out invalid strings before I try to parse them.
I'm thinking to do something like \,\".+\"\, to find a token and then to check that it doesn't contain "," inside. But I can't figure out how to make it work.
I've searched in SO but haven't found an answer which works for me.
Thank you.
If String always start and end with ", you can try with this Java regex:
(?<=,\s{0,99}"|(?!\A)\G)[^"]+|(?<=(?!\A)\G|")(")(?!\s*[,\n]|$)
DEMO
the group 1 capture invalid quotes, you can get the indices with matcher.start(1) and matcher.end(1). \s{0,99} will work only in Java.

Regex get the word after match

I have a log file.
In the log file I have a lot of lines and each line contain something like this:
<h4>adi</h4><small>08/02/2015 11:14:16</small>
The name between h4 tag different in every line also the time
I want to catch, using regex the time and the date in the line where I can find the name "adi", and as I said, there is only one line contains the name "adi".
Btw - the log is html.
This matches your target input:
(?<=^<h4>adi</h4><small>)[^<]+
See live demo.
Warning:Proceed with caution. Regex is not supposed to be used for HTML parsing.Use a parser instead!
(?<=adi</h4>\s*<small>)[^<]+

How to stop regex at the end of line

trying to figure out next case:
I have txt file with parameters
environment=trank
Browser=iexplore
id=1988
Url=www.google.com
maautomate=no
When I parse this txt file with regex pattern like
/environment=([^\s]+)/
I got "trankBrow" as result, or
/Url=([^\s]+)/
I got www.google.commaautomate=no
So why second parameters appended? And how to get "trank" only?
environment=([^\\s]+)
You need to use this. \s in your case is escaping s and so the output is trankBrow because after that s is there.

regex to get any characters including newline until a blank line

This is the sample:
YYYY-MM-DD HH:II:SS Message Log
Message Log
Message Log
YYYY-MM-DD HH:II:SS Message Log
I want to get all characters after the timestamp from the first line including all characters of the succeeding line until the blank line?
This is the expected output:
YYYY-MM-DD HH:II:SS Message Log
Message Log
Message Log
I've tried doing something like this:
/^(\d{4}\-\d{2}\-\d{2} \d{2}\:\d{2}\:\d{2}) ([^\n]*)/s
The first group is the timestamp then the second group I am trying to get all characters including all characters of the succeeding line until the blank line
^[\s\S]*?(?=\n{2,}|$)
Try this.See demo.
https://regex101.com/r/pM9yO9/2
How about:
(\d{4}\-\d{2}\-\d{2} \d{2}\:\d{2}\:\d{2})([\s\S]+?)\n\n
The lines you want are in group 2, the date/time in group 1.