Parsing information between two with JavaScript

I'm a newbie in JavaScript and now I'm trying to parsing all information between two words. For example I have:

ip nat translation max-sessions 20000 interface GigabitEthernet 0/0 ip nat static-napt tcp 192.168.1.254 444 self 444 ip nat static-napt tcp 192.168.1.254 448 self 448 ip nat static-napt udp 192.168.1.254 43161 self 43161 exit

Actually I want to receive all information (including the end of the line) between "interface" and "exit".

-------------Problems Reply------------

Using regexp:

var text = "ip nat translation max-sessions 20000\n\
interface GigabitEthernet 0/0\n\
ip nat static-napt tcp 192.168.1.254 444 self 444\n\
ip nat static-napt tcp 192.168.1.254 448 self 448\n\
ip nat static-napt udp 192.168.1.254 43161 self 43161\n\
exit"

text.match(/interface[\s\S]*exit/)

The [\s\S] does the trick here, it matches spaces and non-spaces, hence all characters.

You can try this

var String=str.substring(str.lastIndexOf("interface"),str.lastIndexOf("exit")-1);

var string = 'ip nat translation max-sessions 20000'+
'interface GigabitEthernet 0/0'+
'ip nat static-napt tcp 192.168.1.254 444 self 444'+
'ip nat static-napt tcp 192.168.1.254 448 self 448'+
'ip nat static-napt udp 192.168.1.254 43161 self 43161'+
'exit';

var info =string.substring(string.lastIndexOf("interface"),string.lastIndexOf("exit"));
console.log(info);

Category:javascript Views:8 Time:2018-12-24

Related post

  • How to pass Facebook Session Information Between two Activities 2011-10-06

    I would like to pass Facebook session information between two acvtivities so that I can authenticate one user in 1st session and use that session information to post a message to a wall in 2nd activity. What's the way of doing this simple task? Shoul

  • python: sending information between two scripts 2010-06-18

    I have two Python scripts in two different locations and cannot be moved. What is the best way to send information between the two scripts? say for example in script1.py i had a string e.g. x = 'teststring' then i need variable 'x' passed to script2.

  • How can I parse a CSV string with Javascript? 2011-12-13

    I have the following type of string var string = "'string, duppi, du', 23, lala" I want to split the string into an array on each comma, but only the commas outside the single quotation marks. I cant figure out the right regex for the split... string

  • Include space between two words Javascript if() statement 2009-12-07

    I'm trying to validate a generic contact form that's provided by my CRM unfortunately they control the server side script that puts the information into the CRM. The name of some of the form fields have spaces in them. How can I accommodate for that?

  • What's the difference in debug information between gcc with and without "-ggdb1" option? 2010-10-11

    By default, gcc will add symbol table to the executable, so gdb will get a readable stack trace. Documentation for -ggdb1 option in gcc man page says: Level 1 produces minimal information, enough for making backtraces in parts of the program that you

  • Parsing information between known variables 2011-04-13

    I dont mean to be a bother and I know this has been asked a thousand times before but i'm just not understanding the concept. I was wondering if somebody could walk me through it, Here is what i'm trying to do: I have a set of information inside an h

  • how to parse remote xml file with javascript/jQuery and phonegap? 2011-06-07

    For phonegap development: is it possible to fetch remote data for phonegape? is it possible to fetch remote json/xml file using ajax/jquery ? XmlHttpRequest can fetch remote xml file ? also any suggestion for it or important link. --------------Solut

  • Share information between two load-balanced IIS servers 2011-06-13

    I've two load-balanced IIS servers, and I need to share some information between them. The information is not related to the user session, so I don't see how a session state provider could help here. I cannot use the database (requirement), and appar

  • How to display route information between two points in Android? 2010-02-03

    I am able to show the route between two geo points in android using google map. Now i want to know how to guide the user like turn right, take left; likewise should display message. How can we achieve this? --------------Solutions------------- There

  • MySQL difference of two rows between two with PHP mysql_num_rows function? 2012-01-12

    Is it possible to somehow calc the difference between two rows of one table? I tried this, but it doesnt work: $diff = mysql_num_rows(" SELECT (`used`-`paid`) FROM `coupons_codes` WHERE `cid`='".$data['cid']."'"); --------------Solutions-------------

  • working with asynctask and json parsing simulataneously between two activities 2011-10-11

    i need some suggestion on how to go about this specific android problem: activity A passes an intent to activity B, B reads it, makes an API call, B receives response, parses it, and updates its views from the response now it works fine except fr a 2

  • How to parse calendar file dates with JavaScript? 2011-12-28

    We need to use JavaScript on the browser to read and parse calendar files (.ics) (also called iCal formats). I wrote a custom function to read these values and then use the JavaScript Date() function to make a data object. Is any easier and better wa

  • How to extract information between two unique words in a large text file 2012-02-10

    I have about 150 text files filled with character information. Each file contains two unique words ()alpha and bravo and i want to extract the text between these unique words and write it to a different file. Manually i can CTRL+F for the two words a

  • Sharing information between two XUL applications 2010-02-27

    I am currently developing a toolbar and sidebar for firefox. I want to have the two share information, but upon loading the .js file I want them to share, it is loaded twice and has two instances instead of one. How can I get the toolbar and the side

  • Not able to parse local xml file with javascript 2011-11-08

    When i try to parse local xml file using simple javascript, the code after xhr.open is not getting executed. <html> <head> <script type="text/javascript"> function createXMLHttpRequestObject() { if (window.XMLHttpRequest) { xhttp=ne

  • Sencha Touch 2: data intigration or how to share dynamic information between sencha and javascript 2012-03-25

    I'd like to start quick. What is my problem: Within ST2 I structured my application with the MVC pattern. I have a store, a model, a controler and the views (for more information scroll down). Workflow: I click a list item (List View with a list of e

  • Sending information between two Windows Froms in C# 2010-02-09

    This might be a novice question. :). Consider the following scenario. Suppose we have two windows forms that are already "loaded" (i.e You can see both the forms) Form 1 contains a textbox and a "submit" button while the form 2 contains a text lable.

  • IE 8 remove line break between nodes with JavaScript 2011-01-02

    Ok i have a list of HTML nodes which should be inline with no spacing between them. The problem is, that the nodes are written from a CMS and therefore will come with all sorts of linebreaks and spaces. Therefore I'm removing the spaces with JS using

  • How To Share Information Between Django and Javascript? 2011-01-17

    So I am pretty new to both Django and Javascript (I am using JQuery) and I am wondering if I am doing a hack or if there are more slick ways to send client-side displayed database ids to the django server-side. Here is my process: I have a dataTable

  • Parsing wiki templates calls with Javascript 2011-03-28

    All that I need is to split the wiki template call to parameter parts. In the very basic scenario it is just splitting by | so {{template|unnamed_parameter|param1=value1}} would be split to {{template, unnamed_parameter, param1=value1 and }}. But thi

  • parse google place json with javascript 2011-05-27

    for any reason this code doesn't seem to work var request = "https://maps.googleapis.com/maps/api/place/search/json?"; request = request + "location="+lat+","+lng+"&"; request = request + "radius=500&"; request = request + "types=&"; requ

  • Grabbing information between key words javascript 2011-07-09

    I have an app that is being fed HTML into a variable. I need to find the url for the first image file in the HTML (if there is a link at all). This is what I have right now: var media = row.content.substring(row.content.indexOf('<img src="') + 1,

  • Parse local JSON file with JavaScript in Webkit 2011-10-11

    I am currently trying to parse a local JSON file on Webkit browsers and I am running into a couple issues. var request = new XMLHttpRequest(); request.open('Get', 'file:///abc/test.json', false); var test = JSON.parse(request.responseText); This howe

  • Differences between two regex JavaScript bookmarklets 2012-02-14

    I'm having some weird issues "improving" a bookmarklet. I took this example from here - it takes a regular expression and highlights text on the page matching the expression - I've reformatted it for easy reading using JSMin for Notepad++: javascript

  • Running query to extract relevant information between two tables. 2013-09-17

    I have two tables . first one contains the name of the current vendors and the second table contains the name of vendors that have been flagged. i want to query the current vendor table for any vendor in the flagged vendor table. the challenge is tha

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.174 (s). 11 q(s)