Strip URL param using coldfusion [duplicate] - coldfusion

This question already has answers here:
Parse a specific variable from a url stored as a string with CFML
(3 answers)
Closed 6 years ago.
I have query whose data contains a url like below, How can I extract the Id value from the url using coldfusion.
http://127.0.0.1/entity/abc.cfm?title=first-page-review&id=476
<cfif findNoCase('/entity/', qry.URL)>
<cfset Param2 = ListGetAt(qry.URL,2,"&")>
<cfoutput>#param2#</cfoutput>
This is giving the output like -> 'id=476', but I need only the numeric ID as the output. I can strip the first 3 chars to get the id, but is there a better way to do it. thanks

Provided your URL variables will always be consistent:
<cfset IDvar1 = "http://127.0.0.1/entity/abc.cfm?title=first-page-review&id=476">
<cfset IDvar2 = ListLast(IDvar1,"=") />
Outputting IDvar2 yields 476.

Related

Remove specific characters from string to tidy up URLs [duplicate]

This question already has answers here:
Extracting rootdomains from URL string in Google Sheets
(3 answers)
Closed 2 years ago.
Hi I have a column of messy URL links within Google Sheets I'm trying to clean up, I want all formats of website links to be the same so that I can run a duplicate check on them.
For example, I have a list of URLs with various http, http://, https:// etc. I am trying to use the REGEXREPLACE tool to remove all http combination elements from the column entries, however cannot get it to work. This is what I have:
Before:
http://www.website1.com/
https://website2.com/
https://www.website3.com/
And I want - After:
website.com
website2.com
website3.com
It is ok if this takes place over a number of formulas and thus columns to the end result.
try:
=ARRAYFORMULA(IFERROR(REGEXEXTRACT(INDEX(SPLIT(
REGEXREPLACE(A1:A, "https?://www.|https?://|www.", ), "/"),,1),
"\.(.+\..+)"), INDEX(IFERROR(SPLIT(
REGEXREPLACE(A1:A, "https?://www.|https?://|www.", ), "/")),,1)))
or shorter:
=INDEX(IFERROR(REGEXEXTRACT(A1:A, "^(?:https?:\/\/)?(?:www\.)?([^\/]+)")))
You can try the following formula
=ArrayFormula(regexreplace(LEFT(P1:P3,LEN(P1:P3)-1),"(.*//www.)|(.*//)",""))
Please do adjust ranges as needed.

How to query in Mongo for a String based on expressions [duplicate]

This question already has answers here:
Matching a Forward Slash with a regex
(9 answers)
Closed 3 years ago.
I have lot of Data in Mongo DB, I wanted to query based on a String value and that value contains a url
"url" : "http://some-host/api/name/service/list/1234/xyz"
I got records count when executed the below query
db.mycollection.find({url:"http://some-host/api/name/service/list/1234/xyz"}).count()
I want to get all the records which match with
some-host/api/name/service/list/
I tried using below saamples
db.mycollection.find({url:"some-host/api/name/service/list/"}).count()
Got zero records
db.mycollection.find({url:/.*"some-host/api/name/service/list/".*/}).count()
Got error
db.mycollection.find({"url":/.*"some-host/api/name/service/list/".*/}).count()
Got error
db.mycollection.find({"url":/.*some-host/api/name/service/list/.*/}).count()
Got Error
db.mycollection.find({"url":/.*some-host//api//name//service//list//.*/}).count()
Got ...
...
Then no response
Did you try with something like this:
db.mycollection.find({'url': {'$regex': 'sometext'}})
Please check also here

convert string to variable coldfusion

I'm a bit stumped on this one..
I currently have a string.
Please enter your variable.firstname here
What i would like to do is find the variable.firstname in the string and convert it to be used as #variable.firstname#
Im using CF8, and ive looked at using findNoCase() but the variable.firstname portion can appear anywhere. I am also trying to use this in a Coldfusion Custom Tag as its to simply display the firstname of the user that could be dynamically populated.
I cant use any other functionality to change it IE = variable['firstname] because the variable could be the result of a dynamic variable i pass in and the query for the content will reside within the custom tag.
<cfset yourNewString = replace(yourOldString,'variable.firstname',
'##variable.firstname##', 'all')>
Note the double pound signs.
I cant use any other functionality to change it IE =
variable['firstname] because the variable could be the result of a
dynamic variable i pass in and the query for the content will reside
within the custom tag.
I'm not sure I understand exactly what you're saying here but if you're saying that variables.firstname is coming from another variable and the .firstname is the dynamic part you could still use array notation.
<cfset myName = "Travis">
<cfset yourName = "user125264">
<cfset myCustomVariable = "myName">
<cfoutput>Hi, My name is #variables[myCustomVariable]#. </cfoutput>
<cfset myCustomVariable = "yourName">
<cfoutput>Your name is #variables[MyCustomVariable]#.</cfoutput>
Output: Hi, My name is Travis. Your name is user125264.
If that isn't what you meant, I apologize.
If you're trying to replace variable.firstname with #variables.firstname# and then also get the value of that variable, you'll need to do the replace <cfset yourNewString = replace(yourOldString,'variable.firstname',
'##variables.firstname##', 'all')> and then wrap the resulting string in an evaluate() function (and an inner de() to prevent CF from evaluating everything): <cfset evaluatedString = evaluate(de(yourNewstring))>.
If there are more variables besides variable.firstname that need this kind of translation, you'll need to get into regex with reReplace() to catch them all in one statement. My regex is rusty, so you'll need to Google that bit on your own. ;o)

ColdFusion-9 "includeEmptyValues"

This is my code:
returnStruct.myList = myList;
returnStruct.first = trim(ListGetAt(myList,3));
returnStruct.last = trim(ListGetAt(myList,13));
returnStruct.address = trim(ListGetAt(myList,15));
returnStruct.city = trim(ListGetAt(myList,2));
returnStruct.state = trim(ListGetAt(myList,9));
Everything is working fine until myList hits empty values and then everything crashes.
I found a command "includeEmptyValues" that I can set to 'yes' but I am not familiar with it and the documentation of ColdFusion 9 isn't the best I've come across.
http://cfquickdocs.com/cf9/#listgetat
Previous versions of ColdFusion (and CF9 by default) counted consecutive delimiters as a single delimiter. So a list that looked like this:
<cfset myList="a,b,,c,,d" />
was considered to have four elements.
Recently added is the "includeEmptyValues" attribute.
listGetAt(list, position [, delimiters, includeEmptyValues ])
So while
<cfset myVar=listGetAt(myList,6) />
will throw an error
<cfset myVar=listGetAt(myList,6,",","true") />
will successfully set myVar to d.
might want to use listToArray(), and ArrayIsDefined(). Play with includeEmptyFields attr and see which behavior you prefer. True = Convert empty elements in a list to empty array entries

Use string function to select all text after specific character

How would I use use a string function to select everything in a variable after the last "/"
http://domain.com/g34/abctest.html
So in this case I would like to select "abctest.html"
Running ColdFusion 8.
Any suggestions?
Um, a bit strange to give very similar answer within few days, but ListLast looks as most compact and straightforward approach:
<cfset filename = ListLast("http://domain.com/g34/abctest.html","/") />
And yes, IMO you should start with this page before asking such questions on SO.
Joe I'd use the listToArray function, passing the "/" as the delimiter, get the length of the array and get the value in the last slot. See sample below
<cfset str = "http://domain.com/g34/abctest.html"/>
<cfset arr = ListToArray(str,"/","false")/>
<cfset val = arr[ArrayLen(arr)]/>
<cfoutput>#str# : #val#</cfoutput>
produces
http://domain.com/g34/abctest.html : abctest.html