I would like to grab the address highlighted in red. "Site Location:" can be easily identified via match(). However, how can I grab the highlighted part only without going over proceeding content, i.e., "You have applied...etc". Please note that the proceeding content won't always start with "You have applied".
What I would do is the following:
Look for "Site Location:"
Grab anything after "Site Location:" until you find empty/blank new line.
Can anyone help me achieving it in Ruby?
Note that the whole text is stored in a string variable.
regex = /\bSite Location:\s+(.*?)\n\s*\n/m
str = "Site Location: Raglan Street
Collingwood Town, Some County
You have applied..."
if md = regex.match(str)
address = md[1].strip.gsub(/^\s+/,'')
puts address
end
Output:
Raglan Street
Collingwood Town, Some County
Note: one thing to watch for is the possibility of different types of newlines. E.g. Microsoft may use \r\n\r\n, etc. in which case you may have to adjust regex accordingly.
Related
I am not a developer but have used Google search and trial and error test scenarios with Zapier for the last few days and have given up on figuring this out myself. I need help!
I'm using the Run JavaScript code step in Zapier and provided the following details to Input Data.
It says: What input data should we provide to your code (as strings) via an object set to a variable named inputData?
I'm using "street" with a street address example "1402 Spring Garden Rd"
What is the code to use that regardless of the street address provided all the numbers and first space are removed so that the results is "Spring Garden Rd"
Thank you in advance!
var street = inputData;
var streetNoNumbers = inputData.replace(/[0-9]/g, '');
return streetNoNumbers
The error message I'm getting is
TypeError: inputData.replace is not a function
I've learned that strings are immutable and a new string can be made from manipulating another string but doing this in zapier seems to require a function and creating another var with the calculation generates a ... is not a function.
I've tried to write a function but can't get the output or return to show the proper results either.
I can do the following successfully,
var street = inputData
return street
1402 Spring Garden Road
I want to include the code that manipulates street to produce the following:
Spring Garden Road
David here, from the Zapier Platform team. Great question!
The key understanding you're missing is that inputData is a js object with a street property. Before your code is run, we set it up like so:
const inputData = {street: '1402 Spring Garden Rd'}
Since inputData is an object, it doesn't have a replace method (the error you're seeing). Instead, perform your operation on .street and return that.
Try the following:
// need to return an object, not just a string
return {streetNoNumbers: inputData.replace(/[0-9]/g, '')}
If you want to learn more, I recommend our simple examples: https://zapier.com/help/code/#simple-email-extraction
I want the Information Message to show two lines of text.
Can this be done using one message class statement. Ex.
MESSAGE i001(z56_myclass) WITH lv_cust_id.
I tried putting the string of the short text with characters \n # \r \\n etc. but nothing worked. I don't know how to use long text editor for this particular requirement. Any help would be great.
You can't control the message carriage return in MESSAGE statement.
You can try instead with the following information popup
call function 'POPUP_TO_INFORM'
exporting
titel = 'Information'
txt1 = 'Registration successful'
txt2 = 'Customer Id is 0000001234'.
You have 4 text rows at your disposal (from txt1 to txt4).
So i have this coming from my web scrape
pastebin.com/CMrFcBMX
What i'm wanting is all the prices and ticket description. Heres what i have
doc.xpath("//script[#type='text/javascript']/text()").each do |text|
if text.content =~ /more_options_on_polling/
price1 = text.to_s.scan(/\"(formatted_(?:total_price))\":\"(.+?)\"/).uniq
description = text.to_s.scan(/\"(ticket_desc)\":\"(.+?)\"/).uniq
price = price1 + description
render json: price
end
end
So this is what i have at the moment. However i'm needing to do some major edits.
Firstly i'm needing the description to ignore any plus symbols, e.g. Later Owl + Chance For VIP Upgrade\ would need to be ignored.
Secondly I need to remove the json rendering nice, So that the first price and fees match with the first description.
Once i have this rendered i should be sorted. I'd be using this in a js file afterwards so a format like this would be best:
Ticket{
[
Price:
Fees:
Description:
]
}
Once i have it like this i should be good to finish my application ^_^
Thanks
Sam
lets say we have some grammar like this.
Model:
greeting+=Greeting*;
Greeting:
'Hello' name=ID '!';
I would like to check whether the text written text in name is a valid text.
All the valid words are saved in an array.
Also the array should be filled with words from a given file.
So is it possible to check this at runtime and maybe also use this words as suggestions.
Thanks
For this purpose you can use a validator.
A simple video tutorial about it can be found here
In your case the function in the validator could look like this:
public static val INVALID_NAME = "greeting_InvalidName"
#Check
def nameIsValid(Greeting grt) {
val name = grt.getName() //or just grt.Name
val validNames = NewArrayList
//add all valid names to this list
if (!validNames.contains(name)) {
val errorMsg = "Name is not valid"
error(errorMsg, GreetingsPackage.eINSTANCE.Greeting_name, INVALID_NAME)
}
}
You might have to replace the "GreetingsPackage" if your DSL isn't named Greetings.
The static String passed to the error-method serves for identification of the error. This gets important when you want to implement Quickfixes which is the second thing you have asked for as they provide the possibility to give the programmer a few ideas how to actually fix this particular problem.
Because I don't have any experience with implementing quickfixes myself I can just give you this as a reference.
I am trying to pass a query to a spreadsheet. I have a value say "John cena". How do I pass it in the following line. I am getting an error while doing so
ListQuery query = new ListQuery(listFeedUrl);
query.setSpreadsheetQuery("name = 'John cena' and age > 25");
ListFeed feed = service.query(query, ListFeed.class);
This is the error im getting:
com.google.gdata.util.InvalidEntryException: Bad Request
Parse error: Invalid token encountered
at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:594)
at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:563)
at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:552)
at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:530)
at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:535)
at com.google.gdata.client.Service.getFeed(Service.java:1135)
at com.google.gdata.client.Service.getFeed(Service.java:1077)
at com.google.gdata.client.GoogleService.getFeed(GoogleService.java:662)
at com.google.gdata.client.Service.query(Service.java:1237)
at com.google.gdata.client.Service.query(Service.java:1178)
I'm sorry I don't know the answer completely, but I want to help.
Can you try something like this:
query.setSpreadsheetQuery("name = \"John cena\" and age > 25");
The wiki post # http://code.google.com/apis/spreadsheets/data/3.0/developers_guide.html#SendingStructuredRowQueries says that you have to include data with space in quotations.
I had the same issue, where I had my item column with values that can contain white spaces. By adding double quotes and escaping it in string, I was able to bypass the issue. Also you might want to remove other spaces in the query, apart from the ones between "and", just in case.
String queryString = ""; //should contain feedURL
ListQuery lsListQuery = new ListQuery(new URI(queryString).toURL());
lsListQuery.setSpreadsheetQuery("item=\"Item Name4\" ");
\\This will have the URI encoded
logger.debug(lsListQuery.getQueryUri());
\\This will give you the complete URL
logger.debug(new URI (queryString+lsListQuery.getQueryUri().toString()).toURL());
\\ This should give the feed from which the columns can be read
ListFeed listFeed = service.getFeed(new URI (queryString+lsListQuery.getQueryUri().toString()).toURL(), ListFeed.class);