Tags:
create new tag
, view all tags

SID-02274: Using escape character in search string and variables

Status: Asked Asked TWiki version: Perl version:
Category: CategorySearch Server OS: CentOS 5.2 Last update: 1 year ago

I believe I'm having an issue properly using the escape character in my code. I have a search string created that works fine, but it's pulling more data than I want. So if the search is for ABC on a certain topic, it's pulls everything with ABC in front of it, exampled ABCD. But I just want it to pull ABC. I had done some searching and found a way to accomplish that in standard code. But when I try to implement it in to code where I have to escape parts of the code, it's breaking the code.

Example 1 of my existing code that is currently pulling more data than I want using Escape characters:

Title Name IP Brand Model SPM # POA# Type User
$percntSEARCH{ web=\"title\" \"[F]orm Field.*?value=.$percntFORMFIELD{\"form field name\" topic=\"$percntINCLUDINGTOPIC$percnt\"}$percnt\" scope=\"text\" topic = \"DATA*\" type=\"regex\" nosearch=\"on\" order=\"formfield(Name)\" nototal=\"on\" format=\"| $formfield(Title) | $formfield(Name) | $formfield(IP) | $formfield(Brand) | $formfield(Model) | $formfield(SPM Number) | $formfield(ID Number) | $formfield(Item Type) | $formfield(Currently Assigned User) | View / Edit |\" }$percnt"

Example 2of the code standard with the fix to only pull specifically the value entered (GBM) in this case, which works. Will not include items that have GBM1, GBM2 etc.

Title Name IP Brand Model S/N SPM # POA# Type User
%SEARCH{ web="title" "[F]orm field.*?value=\"[G]BM\"" scope="text" topic = "DLPID*" type="regex" nosearch="on" order="formfield(Name)" nototal="on" format="| $formfield(title) | $formfield(Name) | $formfield(IP) | $formfield(Brand) | $formfield(Model) | $formfield(S/N) | $formfield(SPM Number) | $formfield(ID Number) | $formfield(Item Type) | $formfield(Currently Assigned User) | View / Edit |" }%

So the fix in this case was changing "[F]orm field.*?value=.[G]BM" to "[F]orm field.*?value=\"[G]BM\"".

However, when i try to apply that same fix to example 1, it breaks the code. Below is how i tried to implement it and I'm sure it's becuase i'm not escaping the code properly but have tried different combinations and it's not working.

Title Name IP Brand Model SPM # POA# Type User
$percntSEARCH{ web=\"title\" \"[F]orm Field.*?value=\"$percntFORMFIELD{\"form field name\" topic=\"$percntINCLUDINGTOPIC$percnt\"}$percnt\"\" scope=\"text\" topic = \"DATA*\" type=\"regex\" nosearch=\"on\" order=\"formfield(Name)\" nototal=\"on\" format=\"| $formfield(Title) | $formfield(Name) | $formfield(IP) | $formfield(Brand) | $formfield(Model) | $formfield(SPM Number) | $formfield(ID Number) | $formfield(Item Type) | $formfield(Currently Assigned User) | View / Edit |\" }$percnt"

This part of the code is where I believe is formatted incorrectly:

Original code that is working but pulling all data that starts with my search value that I don't want: \"[F]orm Field.*?value=.$percntFORMFIELD{\"form field name\" topic=\"$percntINCLUDINGTOPIC$percnt\"}$percnt\"

Fix i tried to apply to code that breaks it: \"[F]orm Field.*?value=\"$percntFORMFIELD{\"form field name\" topic=\"$percntINCLUDINGTOPIC$percnt\"}$percnt\"\"

The error received is: Searched: [F]orm field.*?value=

Sorry, it's a lot of data, but if you can where I might be escaping incorrectly or possibly just trying to go about it the wrong way, it would be appreciated.

TY Chris

-- Christopher Crowe - 2016-10-27

Discussion and Answer

Hi Chris. What you wrote is a little tough to follow for me however I'm wondering if the issue is where you've identified it: [F]orm Field.*?value=\"$percntFORMFIELD{\"form field name\" topic=\"$percntINCLUDINGTOPIC$percnt\"}$percnt\"\"

When you are setting value it appears that value will span up to the first quote (of the same "level") which becomes value="%FORMFIELD[".

If I take a stab are re-writing your search I get the following:

%SEARCH{"[F]ormFieldName.*?value=\"%FORMFIELD{"FormFieldName" topic="%INCLUDINGTOPIC%"}%\"" scope="text" topic= "DATA*" web="WebName" type="regex"  format="| $topic | $formfield(Title) |" }%
I tested it with everything excluding the INCLUDINGTOPIC which I don't think would break it.

Hope this is helpful.

-- Jani Hamalainen - 2016-10-28

Discussion and Answer

Hi, I think your syntax is somewhat unusual. Which it says JaniHamalainen is right here I leave an example of what I have done to make a combined search basing the name of a topic:

Example (code):

| *SPT* | *Type* | *Stage* | *Contact* | *Create Date* |
%SEARCH{ "*;META:FIELD.*name=.GroupName.*value=.*%INCLUDINGTOPIC%;" topic="SPTM*" type="regex" nonoise="on" format="|  [[$topic][$percntCALC{$SUBSTITUTE($topic, SPTM-,)}$percnt]]%BR%[[$topic][<img src=\"%PUBURLPATH%/%TWIKIWEB%/IntellibanksDocGraphics/viewtopic.gif\" alt=\"View entry\" title=\"View entry\" width=\"16\" height=\"16\" border=\"0\" />]][[%SCRIPTURL{edit}%/$web/$topic?t=%SERVERTIME{$hou$min$sec}%][<img src=\"%PUBURLPATH%/%TWIKIWEB%/IntellibanksDocGraphics/edittopic.gif\" alt=\"Edit entry\" title=\"Edit entry\" width=\"16\" height=\"16\" border=\"0\" />]]  | $formfield(Type) | $formfield(Stage) | $percntSEARCH{ \"^$formfield(Client Name)$\" scope=\"topic\" type=\"regex\" nonoise=\"on\" format=\"[[$dollartopic][$dollarformfield(Name)]]\" }$percnt | $formfield(Date) |" }%
Example: sales.jpg
Pablo Jovanni Lopez Garcia - 2016-11-02

Comment

      Change status to:
ALERT! If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.
SupportForm
Status Asked
Title Using escape character in search string and variables
SupportCategory CategorySearch
TWiki version

Server OS CentOS 5.2
Web server Apache/2.0.52
Perl version

Browser & version IE 11 / Chrome 45.0.2454.101 m
Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r3 - 2016-11-02 - PabloLopez
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.