Javascript RegEx inside Perl. Escape Character Madness!
So, I have a perl script that's outputting a page (js functions + html).
I'm running into a problem, though.
What's in my code isn't what comes out in the actual code of the page.
I realized it's probably because of escape characters.
Here's the javascript file:
[html]
function xtractFile(data)
{
var m = data.match(/(.*)[\/\\]([^\/\\]+\.\w+)$/);
return {path: m[1], file: m[2]}
}
[/html]
and here's the html source of the page after being generated:
[html]
var m = data.match(/(.*)[/\]([^/\]+.w+));
[/html]
the regex is stripping out the filename from a full path.
i.e. C:\Folder1\Folder2\Folder3\filename.pdf becomes filename.pdf
I've been doing OK with Perl, but regex is really throwing me.
I'm sure I'm going to come across this again in the future, so I was hoping I might get some enlightenment on how to handle this kind of situation.
I'm running into a problem, though.
What's in my code isn't what comes out in the actual code of the page.
I realized it's probably because of escape characters.
Here's the javascript file:
[html]
function xtractFile(data)
{
var m = data.match(/(.*)[\/\\]([^\/\\]+\.\w+)$/);
return {path: m[1], file: m[2]}
}
[/html]
and here's the html source of the page after being generated:
[html]
var m = data.match(/(.*)[/\]([^/\]+.w+));
[/html]
the regex is stripping out the filename from a full path.
i.e. C:\Folder1\Folder2\Folder3\filename.pdf becomes filename.pdf
I've been doing OK with Perl, but regex is really throwing me.
I'm sure I'm going to come across this again in the future, so I was hoping I might get some enlightenment on how to handle this kind of situation.
0
Comments
-
Figured this out via another forum, but I wanted to post what I found.
I needed to keep my javascript regex out of the perl interpolation.
[html]
$javascript = <<'JAVASCRIPT';
function xtractFile(data)
{
alert ("Data: " + data);
var m = data.match(/(.*)[\/\\]([^\/\\]+\.\w+)$/);
alert (m[1]);
alert (m[2]);
// return {path: m[1], file: m[2]};
}
JAVASCRIPT
[/html]
Then right under it I start the regular HTML where I actually need some perl variables.
[html]
print <<"END";
File Upload Utility
...
<SCRIPT LANGUAGE="JavaScript">
function example(){
alert ($PerlVariable);
}
END
[/html]
I didn't know you could split it up into sections like that.
Hopefully this will help someone else.0 -
You can even mix'em up! Try the following sample, see what happens
$not = '';
print <<BOO, <<'FOO';
Section BOO is $not evaluated
BOO
Section FOO is $not evaluated
FOO
Isn't Perl wonderful?0 -
Thou Shalt Know and Love Thy Toolsyou are evil. scaring people. 0 -
More on...escape characters in JavaScript
0
Categories
- All Categories
- 107 Developer Announcements
- 53 Articles
- 104 General Questions
- 141 IM Services
- 43 OpenText Hackathon
- 32 Developer Tools
- 20.6K Analytics
- 4.1K AppWorks
- 8.9K Extended ECM
- 898 Cloud Fax and Notifications
- 76 Digital Asset Management
- 9.3K Documentum
- 29 eDOCS
- 118 Exstream
- 39.8K TeamSite
- 1.7K Web Experience Management
TeamSite Developer Resources
If you are interested in gaining full access to the content, you can register for a My Support account here.
- Docker Automation
- LiveSite Content Services (LSCS) REST API
- Single Page Application (SPA) Modules
- TeamSite Add-ons
If you are interested in gaining full access to the content, you can register for a My Support account here.