정규식 표현 정리

2019. 3. 28. 10:53

역슬레쉬

'use strict';

const string = '<h1>::: buy - 99,000 won :::</h1>';
const result1 = string.replace(/<h1>/g, '');
console.log('result1 :', result1);


const result2 = string.replace(/<h1>/g, '').replace(/<\/h1>/g, '');

// 역슬러쉬 정규식 표현시 앞에 사용
console.log('result2 :', result2);


 

.점

const string = '<h1>::: buy - </h1> <h2> 99,000 won :::</h2>';


const result1 = string.replace(/<..>/g, '');       // <..> 괄호속 어떤 문자2개면 삭제
const result2 = string.replace(/<.../g, '');        // <...  왼괄호 후  문자열3개 삭제


console.log('<..> : ', result1);
console.log('<...> : ', result2);

 

중괄호

'use strict';


const string = '<h1>::: buy - </h1> <h2> 99,000 won :::</h2>';
const stringDiv = '<div>::: buy - </div> <h2> 99,000 won :::</h2>';

const replaceH1 = string.replace(/<.{0,1}h1> /g, '');  // h1앞에 0,1글짜
const replaceTags = string.replace(/<.{0,4}> /g, '');  // > 앞에 0,4글짜

console.log(replaceH1);
console.log(replaceTags);

 

[]

const string = '<h1>::: buy - </h1> <h2> 99,000 won :::</h2>';

const Bracket = string.replace(/[()]/g, '');
const BracketComma = string.replace(/[()/\-,]/g, '');

 


console.log('before 전: ', string);
console.log('()after : ', Bracket);
console.log('/after : ', BracketComma);

 

 

 

 

'' 카테고리의 다른 글

express + morgan  (0) 2019.04.01
promise  (0) 2019.03.28
DB에 웹쉘코드 삽입 POC  (0) 2018.12.06
워드프레스 서버 이관  (0) 2018.09.03
PHPMailer 구글 SMTP 메일 보내기  (0) 2018.08.23
블로그 이미지

iesay

,

tron Token Balance (trc10)

트론 2019. 1. 29. 10:45

한 3일 삽질 한거 같은데 잘 안된다.

 

어제 자바스크립트 5만줄짜리 분석해보고 코딩 한줄도 못하고

오늘 다시 TronLink부터 차근 차근 분석 해볼려구 한다.

 

오늘 안에 제발 완료 되면 좋겠다.

 

시간은 잘 가서 좋긴한데 ㅎ

조금 답답한 면도 있다.

 

 

https://apilist.tronscan.org/api/account?address=TRWkuqvtjc6FXsbJhpnJNG7bB6CAwu6dfM

 

결과 json은 아래에서 파싱 하면 된다.

https://jsoneditoronline.org/

 

정말 허무하다.

아무거나 마음에 드는거 쓰면 된다.

router.get('/tokenBalance/:Address',function(req,res,next) {
 const app = async () => {
         try {
                const Add = req.params.Address;
                const gBalance = await tronWeb.trx.getAccount(Add);
                var token = gBalance.assetV2[0].value;
                res.json( { "getBalance  ": token})

                }catch (error) { console.log('Task Failure',error);
                }
        };
app();
});

 

블로그 이미지

iesay

,

nodejs - form submit

시스템 2019. 1. 22. 11:33

새로고침 없는 비동기로 새로운 방식이라고 한다.

 

 

nodejs - form submit

 

app.js


const express = require('express');
const app = express();
const bodyParser = require('body-parser');

app.use(express.static('public'));
app.use(bodyParser.urlencoded({extended: true}));

app.get('/', (req, res) => {
    res.sendfile('public/index.html');
});

app.post('/login', (req, res) => {
        console.log(req.body.userId, req.body.userPw);
    if(req.body.userId==='admin'&&req.body.userPw==='1234'){
        res.json({success:true});
    }else{
        res.json({success:false});
    }
});

app.listen(8000);

console.log("open 8000");


module.exports = app;


 

 

public/index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="//code.jquery.com/jquery-latest.min.js"></script>
    <title>Hello</title>
    <script>
        $(document).ready(function (){
            $('#login').click(function () {
                $.ajax({
                    url: 'http://192.168.0.118:8000/login',
                    method : 'POST',
                    data: {userId : $('#id').val(), userPw: $('#pw').val()},
                    dataType: 'json'
                }).done(function(data){
                    if(data.success)
                        alert('로그인 성공');
                    else
                        alert('로그인 실패');
                }).fail(function (data){
                    alert('로그인 오류');
                })
            });
        });
    </script>
</head>
<body>
    <h1>로그인페이지</h1>
    <hr>
    아이디 <input type="text" id='id'>
    패스워드 <input type="password" id='pw'>
    <button id="login">로그인</button>

</body>
</html>

 

실행 결과

 

미들웨어 처리 함

root@tkpark-VirtualBox:~/project/myapp# yarn start
yarn run v1.13.0
$ node ./bin/www
open 8000
admin 1234
admin 1
admin 1
admin 1234
admin 1234

 

 

http://192.168.0.118:8000/

이제 기존의 route랑 연동해야겠다.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'시스템' 카테고리의 다른 글

시놀리지 나스 synology nas(redmine plugin)설치  (2) 2019.04.29
pm2  (0) 2019.03.28
nodejs + mariadb 연동  (0) 2019.01.14
nodejs json파일 MongDB에 입력  (0) 2018.12.04
nodejs json파일 컨트롤  (0) 2018.12.04
블로그 이미지

iesay

,